From 4492bf33aa6a9123e477e79c8c20204e4112371b Mon Sep 17 00:00:00 2001 From: Seiun <140777969+lonh-jing@users.noreply.github.com> Date: Wed, 11 Feb 2026 16:41:50 +0800 Subject: [PATCH] fix(webui): support newly added model-calling component in task mapping/cards --- webui/dist/assets/index-DD4VGX3W.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webui/dist/assets/index-DD4VGX3W.js b/webui/dist/assets/index-DD4VGX3W.js index d54d300c..9b0c8338 100644 --- a/webui/dist/assets/index-DD4VGX3W.js +++ b/webui/dist/assets/index-DD4VGX3W.js @@ -69,7 +69,7 @@ ${h}`:m||h}function GS(a,{maxDepth:l=1e3,numbersAsFloat:r=!1}={}){if(vc(a)!=="ob Checking pack provider: ${f.name}`),console.log(` Pack URL: ${f.base_url}`),console.log(` Normalized: ${Pm(f.base_url)}`);const p=m.filter(g=>{const N=Pm(g.base_url),j=Pm(f.base_url);return console.log(` Comparing with local "${g.name}": ${g.base_url}`),console.log(` Local normalized: ${N}`),console.log(` Match: ${N===j}`),N===j});p.length>0?(console.log(` ✓ Matched with ${p.length} local provider(s):`,p.map(g=>g.name).join(", ")),d.existing_providers.push({pack_provider:f,local_providers:p.map(g=>({name:g.name,base_url:g.base_url}))})):(console.log(" ✗ No match found - will need API key"),d.new_providers.push(f))}const h=c.models||[];console.log(` === Model Conflict Detection ===`);for(const f of a.models){const p=h.find(g=>g.name===f.name);p&&(console.log(`Model conflict: ${f.name}`),d.conflicting_models.push({pack_model:f.name,local_model:p.name}))}return console.log(` === Detection Summary ===`),console.log(`Existing providers: ${d.existing_providers.length}`),console.log(`New providers: ${d.new_providers.length}`),console.log(`Conflicting models: ${d.conflicting_models.length}`),console.log(`=========================== -`),d}async function g4(a,l,r,c){const d=await ke("/api/webui/config/model");if(!d.ok)throw new Error("获取当前模型配置失败");const m=await d.json(),h=m.config||m;if(l.apply_providers){const p=l.selected_providers?a.providers.filter(g=>l.selected_providers.includes(g.name)):a.providers;for(const g of p){if(r[g.name])continue;const N=c[g.name];if(!N)throw new Error(`提供商 "${g.name}" 缺少 API Key`);const j={...g,api_key:N},b=h.api_providers.findIndex(y=>y.name===g.name);b>=0?h.api_providers[b]=j:h.api_providers.push(j)}}if(l.apply_models){const p=l.selected_models?a.models.filter(g=>l.selected_models.includes(g.name)):a.models;for(const g of p){const N=r[g.api_provider]||g.api_provider,j={...g,api_provider:N},b=h.models.findIndex(y=>y.name===g.name);b>=0?h.models[b]=j:h.models.push(j)}}if(l.apply_task_config){const p=l.selected_tasks||Object.keys(a.task_config);for(const g of p){const N=a.task_config[g];if(!N)continue;const j=new Set(l.selected_models||a.models.map(w=>w.name)),b=N.model_list.filter(w=>j.has(w));if(b.length===0)continue;const y={...N,model_list:b};if(l.task_mode==="replace")h.model_task_config[g]=y;else{const w=h.model_task_config[g];if(w){const z=[...new Set([...w.model_list,...b])];h.model_task_config[g]={...w,model_list:z}}else h.model_task_config[g]=y}}}if(!(await ke("/api/webui/config/model",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(h)})).ok)throw new Error("保存配置失败")}async function j4(a){const l=await ke("/api/webui/config/model");if(!l.ok)throw new Error("获取当前模型配置失败");const r=await l.json();if(!r.success||!r.config)throw new Error("获取配置失败");const c=r.config;let d=(c.api_providers||[]).map(g=>({name:g.name,base_url:g.base_url,client_type:g.client_type,max_retry:g.max_retry,timeout:g.timeout,retry_interval:g.retry_interval}));a.selectedProviders&&(d=d.filter(g=>a.selectedProviders.includes(g.name)));let m=c.models||[];a.selectedModels&&(m=m.filter(g=>a.selectedModels.includes(g.name)));const h={},f=c.model_task_config||{},p=a.selectedTasks||Object.keys(f);for(const g of p)f[g]&&(h[g]=f[g]);return{providers:d,models:m,task_config:h}}function Pm(a){try{const l=new URL(a);return`${l.protocol}//${l.host}${l.pathname}`.replace(/\/$/,"").toLowerCase()}catch{return a.toLowerCase().replace(/\/$/,"")}}function cN(){const a="maibot_pack_user_id";let l=localStorage.getItem(a);return l||(l="pack_user_"+Math.random().toString(36).substring(2,15),localStorage.setItem(a,l)),l}const v4={utils:"通用工具",utils_small:"轻量工具",tool_use:"工具调用",replyer:"回复生成",planner:"规划推理",vlm:"视觉模型",voice:"语音处理",embedding:"向量嵌入",lpmm_entity_extract:"实体提取",lpmm_rdf_build:"RDF构建",lpmm_qa:"问答模型"},N4=["官方推荐","性价比","高性能","免费模型","国内可用","海外模型","OpenAI","Claude","Gemini","国产模型","多模态","轻量级"];function b4({trigger:a}){const[l,r]=u.useState(!1),[c,d]=u.useState(1),[m,h]=u.useState(!1),[f,p]=u.useState(!1),[g,N]=u.useState([]),[j,b]=u.useState([]),[y,w]=u.useState({}),[z,M]=u.useState(new Set),[S,F]=u.useState(new Set),[E,C]=u.useState(new Set),[R,H]=u.useState(""),[O,X]=u.useState(""),[L,me]=u.useState(""),[Ne,je]=u.useState([]);u.useEffect(()=>{l&&c===1&&ce()},[l,c]);const ce=async()=>{h(!0);try{const G=await j4({name:"",description:"",author:""});N(G.providers),b(G.models),w(G.task_config),M(new Set(G.providers.map($=>$.name))),F(new Set(G.models.map($=>$.name))),C(new Set(Object.keys(G.task_config)))}catch(G){console.error("加载配置失败:",G),aa({title:"加载当前配置失败",variant:"destructive"})}finally{h(!1)}},ge=G=>{const $=new Set(z),A=new Set(S),K=new Set(E);$.has(G)?($.delete(G),j.filter(se=>se.api_provider===G).forEach(se=>A.delete(se.name)),Object.entries(y).forEach(([se,$e])=>{$e.model_list&&($e.model_list.some(J=>A.has(J))||K.delete(se))})):($.add(G),j.filter(se=>se.api_provider===G).forEach(se=>A.add(se.name)),Object.entries(y).forEach(([se,$e])=>{$e.model_list&&$e.model_list.some(J=>{const Z=j.find(Le=>Le.name===J);return Z&&Z.api_provider===G})&&K.add(se)})),M($),F(A),C(K)},pe=G=>{const $=new Set(S),A=new Set(E);$.has(G)?($.delete(G),Object.entries(y).forEach(([K,Re])=>{Re.model_list&&(Re.model_list.some($e=>$.has($e))||A.delete(K))})):($.add(G),Object.entries(y).forEach(([K,Re])=>{Re.model_list&&Re.model_list.includes(G)&&A.add(K)})),F($),C(A)},D=G=>{const $=new Set(E);$.has(G)?$.delete(G):$.add(G),C($)},Q=G=>{Ne.includes(G)?je(Ne.filter($=>$!==G)):Ne.length<5?je([...Ne,G]):aa({title:"最多选择 5 个标签",variant:"destructive"})},B=()=>{z.size===g.length?M(new Set):M(new Set(g.map(G=>G.name)))},ue=()=>{S.size===j.length?F(new Set):F(new Set(j.map(G=>G.name)))},Y=()=>{const G=Object.keys(y);E.size===G.length?C(new Set):C(new Set(G))},we=async()=>{if(!R.trim()){aa({title:"请输入模板名称",variant:"destructive"});return}if(!O.trim()){aa({title:"请输入模板描述",variant:"destructive"});return}if(!L.trim()){aa({title:"请输入作者名称",variant:"destructive"});return}if(z.size===0&&S.size===0&&E.size===0){aa({title:"请至少选择一项配置",variant:"destructive"});return}p(!0);try{const G=g.filter(K=>z.has(K.name)),$=j.filter(K=>S.has(K.name)),A={};for(const[K,Re]of Object.entries(y))E.has(K)&&(A[K]=Re);await h4({name:R.trim(),description:O.trim(),author:L.trim(),tags:Ne,providers:G,models:$,task_config:A}),aa({title:"模板已提交审核,审核通过后将显示在市场中"}),r(!1),fe()}catch(G){console.error("提交失败:",G),aa({title:G instanceof Error?G.message:"提交失败",variant:"destructive"})}finally{p(!1)}},fe=()=>{d(1),H(""),X(""),me(""),je([]),M(new Set),F(new Set),C(new Set)},Ee=2;return e.jsxs(Qs,{open:l,onOpenChange:r,children:[e.jsx(dd,{asChild:!0,children:a||e.jsxs(_,{variant:"outline",children:[e.jsx(mv,{className:"w-4 h-4 mr-2"}),"分享配置"]})}),e.jsxs(Hs,{className:"max-w-2xl max-h-[85vh] flex flex-col",children:[e.jsxs(qs,{children:[e.jsxs(Vs,{className:"flex items-center gap-2",children:[e.jsx(xa,{className:"w-5 h-5"}),"分享配置模板"]}),e.jsxs(at,{children:["步骤 ",c," / ",Ee,":",c===1&&"选择要分享的配置",c===2&&"填写模板信息"]})]}),e.jsx(ts,{className:"h-[calc(85vh-220px)] pr-4",children:m?e.jsxs("div",{className:"py-8 text-center",children:[e.jsx(Fs,{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(ht,{children:[e.jsx(Yt,{className:"h-4 w-4"}),e.jsx(Jn,{children:"安全提示"}),e.jsxs(ft,{children:["分享的配置将",e.jsx("strong",{children:"不包含"})," API Key,其他用户需要自行配置。"]})]}),e.jsxs(Jt,{defaultValue:"providers",className:"w-full",children:[e.jsxs(Gt,{className:"grid w-full grid-cols-3",children:[e.jsxs(Xe,{value:"providers",children:[e.jsx(Hl,{className:"w-4 h-4 mr-2"}),"API 提供商",e.jsxs(Ce,{variant:"secondary",className:"ml-2",children:[z.size,"/",g.length]})]}),e.jsxs(Xe,{value:"models",children:[e.jsx(Wn,{className:"w-4 h-4 mr-2"}),"模型配置",e.jsxs(Ce,{variant:"secondary",className:"ml-2",children:[S.size,"/",j.length]})]}),e.jsxs(Xe,{value:"tasks",children:[e.jsx(er,{className:"w-4 h-4 mr-2"}),"任务配置",e.jsxs(Ce,{variant:"secondary",className:"ml-2",children:[E.size,"/",Object.keys(y).length]})]})]}),e.jsx(Ss,{value:"providers",className:"space-y-2 mt-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(_,{variant:"ghost",size:"sm",onClick:B,children:z.size===g.length?"取消全选":"全选"})}),g.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-2",children:"暂无提供商配置"}):g.map(G=>e.jsxs("div",{className:"flex items-center space-x-2 p-2 rounded hover:bg-muted",children:[e.jsx(tt,{id:`provider-${G.name}`,checked:z.has(G.name),onCheckedChange:()=>ge(G.name)}),e.jsxs(T,{htmlFor:`provider-${G.name}`,className:"flex-1 cursor-pointer",children:[e.jsx("span",{className:"font-medium",children:G.name}),e.jsx("span",{className:"text-xs text-muted-foreground ml-2",children:G.base_url})]}),e.jsx(Ce,{variant:"outline",className:"text-xs",children:G.client_type})]},G.name))]})}),e.jsx(Ss,{value:"models",className:"space-y-2 mt-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(_,{variant:"ghost",size:"sm",onClick:ue,children:S.size===j.length?"取消全选":"全选"})}),j.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-2",children:"暂无模型配置"}):j.map(G=>e.jsxs("div",{className:"flex items-center space-x-2 p-2 rounded hover:bg-muted",children:[e.jsx(tt,{id:`model-${G.name}`,checked:S.has(G.name),onCheckedChange:()=>pe(G.name)}),e.jsxs(T,{htmlFor:`model-${G.name}`,className:"flex-1 cursor-pointer",children:[e.jsx("span",{className:"font-medium",children:G.name}),e.jsx("span",{className:"text-xs text-muted-foreground ml-2",children:G.model_identifier})]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:G.api_provider})]},G.name))]})}),e.jsx(Ss,{value:"tasks",className:"space-y-2 mt-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(_,{variant:"ghost",size:"sm",onClick:Y,children:E.size===Object.keys(y).length?"取消全选":"全选"})}),Object.keys(y).length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-2",children:"暂无任务配置"}):Object.entries(y).map(([G,$])=>e.jsxs("div",{className:"space-y-2 p-2 rounded hover:bg-muted",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(tt,{id:`task-${G}`,checked:E.has(G),onCheckedChange:()=>D(G)}),e.jsx(T,{htmlFor:`task-${G}`,className:"flex-1 cursor-pointer",children:e.jsx("span",{className:"font-medium",children:v4[G]||G})}),e.jsxs(Ce,{variant:"outline",className:"text-xs",children:[$.model_list.length," 个模型"]})]}),$.model_list&&$.model_list.length>0&&e.jsx("div",{className:"ml-6 flex flex-wrap gap-1",children:$.model_list.map(A=>{const K=j.find(se=>se.name===A),Re=S.has(A);return e.jsxs(Ce,{variant:Re?"default":"outline",className:"text-xs cursor-pointer hover:opacity-80 transition-opacity",onClick:()=>pe(A),children:[A,K&&e.jsxs("span",{className:"ml-1 opacity-70",children:["(",K.api_provider,")"]})]},A)})})]},G))]})})]})]}),c===2&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-4 text-sm p-3 bg-muted rounded-lg",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Hl,{className:"w-4 h-4"}),z.size," 个提供商"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Wn,{className:"w-4 h-4"}),S.size," 个模型"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(er,{className:"w-4 h-4"}),E.size," 个任务"]})]}),e.jsx(la,{}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"pack-name",children:"模板名称 *"}),e.jsx(ne,{id:"pack-name",placeholder:"例如:高性价比国产模型配置",value:R,onChange:G=>H(G.target.value),maxLength:50}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[R.length,"/50"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"pack-description",children:"模板描述 *"}),e.jsx(pt,{id:"pack-description",placeholder:"详细描述这个配置模板的特点、适用场景等...",value:O,onChange:G=>X(G.target.value),rows:4,maxLength:500}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[O.length,"/500"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"pack-author",children:"作者名称 *"}),e.jsx(ne,{id:"pack-author",placeholder:"你的昵称或 ID",value:L,onChange:G=>me(G.target.value),maxLength:30})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"标签(可选,最多 5 个)"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:N4.map(G=>e.jsxs(Ce,{variant:Ne.includes(G)?"default":"outline",className:"cursor-pointer transition-colors",onClick:()=>Q(G),children:[Ne.includes(G)&&e.jsx(Ot,{className:"w-3 h-3 mr-1"}),e.jsx(cd,{className:"w-3 h-3 mr-1"}),G]},G))})]})]}),e.jsxs(ht,{children:[e.jsx(Yt,{className:"h-4 w-4"}),e.jsx(Jn,{children:"审核说明"}),e.jsx(ft,{children:"提交后需要经过审核才能在市场中展示。审核通常在 1-3 个工作日内完成。"})]})]})]})}),e.jsxs(gt,{className:"flex justify-between pt-4 border-t",children:[e.jsx("div",{children:c>1&&e.jsx(_,{variant:"outline",onClick:()=>d(c-1),disabled:f,children:"上一步"})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(_,{variant:"outline",onClick:()=>{r(!1),fe()},disabled:f,children:"取消"}),cd(c+1),disabled:m||z.size===0&&S.size===0&&E.size===0,children:"下一步"}):e.jsxs(_,{onClick:we,disabled:f,children:[f&&e.jsx(Fs,{className:"w-4 h-4 mr-2 animate-spin"}),"提交审核"]})]})]})]})]})}function y4({value:a,label:l,onRemove:r}){const{attributes:c,listeners:d,setNodeRef:m,transform:h,transition:f,isDragging:p}=Cv({id:a}),g={transform:Tv.Transform.toString(h),transition:f,opacity:p?.5:1},N=b=>{b.preventDefault(),b.stopPropagation(),r(a)},j=b=>{b.stopPropagation()};return e.jsx("div",{ref:m,style:g,className:P("inline-flex items-center gap-1",p&&"shadow-lg"),children:e.jsxs(Ce,{variant:"secondary",className:"cursor-move hover:bg-secondary/80 flex items-center gap-1",children:[e.jsx("div",{...c,...d,className:"cursor-grab active:cursor-grabbing flex items-center",children:e.jsx(dv,{className:"h-3 w-3 text-muted-foreground"})}),e.jsx("span",{children:l}),e.jsx("span",{role:"button",tabIndex:0,className:"ml-1 rounded-sm hover:bg-destructive/20 focus:outline-none focus:ring-1 focus:ring-destructive cursor-pointer",onClick:N,onPointerDown:j,onMouseDown:b=>b.stopPropagation(),onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),N(b))},children:e.jsx(Sa,{className:"h-3 w-3 hover:text-destructive",strokeWidth:2,fill:"none"})})]})})}function w4({options:a,selected:l,onChange:r,placeholder:c="选择选项...",emptyText:d="未找到选项",className:m}){const[h,f]=u.useState(!1),p=vv(Qo(yv,{activationConstraint:{distance:8}}),Qo(bv,{coordinateGetter:Nv})),g=b=>{l.includes(b)?r(l.filter(y=>y!==b)):r([...l,b])},N=b=>{r(l.filter(y=>y!==b))},j=b=>{const{active:y,over:w}=b;if(w&&y.id!==w.id){const z=l.indexOf(y.id),M=l.indexOf(w.id);r(wv(l,z,M))}};return e.jsxs(cl,{open:h,onOpenChange:f,children:[e.jsx(ol,{asChild:!0,children:e.jsxs(_,{variant:"outline",role:"combobox","aria-expanded":h,className:P("w-full justify-between min-h-10 h-auto",m),children:[e.jsx(_v,{sensors:p,collisionDetection:Sv,onDragEnd:j,children:e.jsx(kv,{items:l,strategy:p_,children:e.jsx("div",{className:"flex gap-1 flex-wrap flex-1",children:l.length===0?e.jsx("span",{className:"text-muted-foreground",children:c}):l.map(b=>{const y=a.find(w=>w.value===b);return e.jsx(y4,{value:b,label:y?.label||b,onRemove:N},b)})})})}),e.jsx(mx,{className:"ml-2 h-4 w-4 shrink-0 opacity-50",strokeWidth:2,fill:"none"})]})}),e.jsx(tl,{className:"w-full p-0",align:"start",children:e.jsxs(md,{children:[e.jsx(xd,{placeholder:"搜索...",className:"h-9"}),e.jsxs(hd,{children:[e.jsx(fd,{children:d}),e.jsx(uc,{children:a.map(b=>{const y=l.includes(b.value);return e.jsxs(mc,{value:b.value,onSelect:()=>g(b.value),children:[e.jsx("div",{className:P("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",y?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(Ot,{className:"h-3 w-3",strokeWidth:2,fill:"none"})}),e.jsx("span",{children:b.label})]},b.value)})})]})]})})]})}const Ul=Bs.memo(function({title:l,description:r,taskConfig:c,modelNames:d,onChange:m,hideTemperature:h=!1,hideMaxTokens:f=!1,dataTour:p}){const g=N=>{m("model_list",N)};return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-base sm:text-lg",children:l}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground mt-1",children:r})]}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-2","data-tour":p,children:[e.jsx(T,{children:"模型列表"}),e.jsx(w4,{options:d.map(N=>({label:N,value:N})),selected:c.model_list||[],onChange:g,placeholder:"选择模型...",emptyText:"暂无可用模型"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[!h&&e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{children:"温度"}),e.jsx(ne,{type:"number",step:"0.1",min:"0",max:"1",value:c.temperature??.3,onChange:N=>{const j=parseFloat(N.target.value);!isNaN(j)&&j>=0&&j<=1&&m("temperature",j)},className:"w-20 h-8 text-sm"})]}),e.jsx(el,{value:[c.temperature??.3],onValueChange:N=>m("temperature",N[0]),min:0,max:1,step:.1,className:"w-full"})]}),!f&&e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"最大 Token"}),e.jsx(ne,{type:"number",step:"1",min:"1",value:c.max_tokens??1024,onChange:N=>m("max_tokens",parseInt(N.target.value))})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{children:"慢请求阈值 (秒)"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"超时警告"})]}),e.jsx(ne,{type:"number",step:"1",min:"1",value:c.slow_threshold??15,onChange:N=>{const j=parseInt(N.target.value);!isNaN(j)&&j>=1&&m("slow_threshold",j)},placeholder:"15"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"模型响应时间超过此阈值将输出警告日志"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"模型选择策略"}),e.jsxs(Pe,{value:c.selection_strategy??"balance",onValueChange:N=>m("selection_strategy",N),children:[e.jsx(Be,{children:e.jsx(Fe,{placeholder:"选择模型选择策略"})}),e.jsxs(Ie,{children:[e.jsx(W,{value:"balance",children:"负载均衡(balance)"}),e.jsx(W,{value:"random",children:"随机选择(random)"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"负载均衡:优先选择使用次数少的模型。随机选择:完全随机从模型列表中选择"})]})]})]})}),_4=Bs.memo(function({paginatedModels:l,allModels:r,onEdit:c,onDelete:d,isModelUsed:m,searchQuery:h}){return l.length===0?e.jsx("div",{className:"md:hidden text-center text-muted-foreground py-8 rounded-lg border bg-card",children:h?"未找到匹配的模型":"暂无模型配置"}):e.jsx("div",{className:"md:hidden space-y-3",children:l.map((f,p)=>{const g=r.findIndex(j=>j===f),N=m(f.name);return e.jsxs("div",{className:"rounded-lg border bg-card p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("h3",{className:"font-semibold text-base",children:f.name}),e.jsx(Ce,{variant:N?"default":"secondary",className:N?"bg-green-600 hover:bg-green-700":"",children:N?"已使用":"未使用"})]}),e.jsx("p",{className:"text-xs text-muted-foreground break-all",title:f.model_identifier,children:f.model_identifier})]}),e.jsxs("div",{className:"flex gap-1 flex-shrink-0",children:[e.jsxs(_,{variant:"default",size:"sm",onClick:()=>c(f,g),children:[e.jsx(Zn,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"编辑"]}),e.jsxs(_,{size:"sm",onClick:()=>d(g),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(os,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"删除"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"提供商"}),e.jsx("p",{className:"font-medium",children:f.api_provider})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"模型温度"}),e.jsx("p",{className:"font-medium",children:f.temperature!=null?f.temperature:e.jsx("span",{className:"text-muted-foreground",children:"默认"})})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"输入价格"}),e.jsxs("p",{className:"font-medium",children:["¥",f.price_in,"/M"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"输出价格"}),e.jsxs("p",{className:"font-medium",children:["¥",f.price_out,"/M"]})]})]})]},p)})})}),S4=Bs.memo(function({paginatedModels:l,allModels:r,filteredModels:c,selectedModels:d,onEdit:m,onDelete:h,onToggleSelection:f,onToggleSelectAll:p,isModelUsed:g,searchQuery:N}){return e.jsx("div",{className:"hidden md:block rounded-lg border bg-card overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(ql,{children:[e.jsx(Vl,{children:e.jsxs(_t,{children:[e.jsx(ns,{className:"w-12",children:e.jsx(tt,{checked:d.size===c.length&&c.length>0,onCheckedChange:p})}),e.jsx(ns,{className:"w-24",children:"使用状态"}),e.jsx(ns,{children:"模型名称"}),e.jsx(ns,{children:"模型标识符"}),e.jsx(ns,{children:"提供商"}),e.jsx(ns,{className:"text-center",children:"温度"}),e.jsx(ns,{className:"text-right",children:"输入价格"}),e.jsx(ns,{className:"text-right",children:"输出价格"}),e.jsx(ns,{className:"text-right",children:"操作"})]})}),e.jsx(Gl,{children:l.length===0?e.jsx(_t,{children:e.jsx(Ze,{colSpan:9,className:"text-center text-muted-foreground py-8",children:N?"未找到匹配的模型":"暂无模型配置"})}):l.map((j,b)=>{const y=r.findIndex(z=>z===j),w=g(j.name);return e.jsxs(_t,{children:[e.jsx(Ze,{children:e.jsx(tt,{checked:d.has(y),onCheckedChange:()=>f(y)})}),e.jsx(Ze,{children:e.jsx(Ce,{variant:w?"default":"secondary",className:w?"bg-green-600 hover:bg-green-700":"",children:w?"已使用":"未使用"})}),e.jsx(Ze,{className:"font-medium",children:j.name}),e.jsx(Ze,{className:"max-w-xs truncate",title:j.model_identifier,children:j.model_identifier}),e.jsx(Ze,{children:j.api_provider}),e.jsx(Ze,{className:"text-center",children:j.temperature!=null?j.temperature:e.jsx("span",{className:"text-muted-foreground",children:"-"})}),e.jsxs(Ze,{className:"text-right",children:["¥",j.price_in,"/M"]}),e.jsxs(Ze,{className:"text-right",children:["¥",j.price_out,"/M"]}),e.jsx(Ze,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(_,{variant:"default",size:"sm",onClick:()=>m(j,y),children:[e.jsx(Zn,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"编辑"]}),e.jsxs(_,{size:"sm",onClick:()=>h(y),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(os,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"删除"]})]})})]},b)})})]})})})}),k4=300*1e3,Zg=new Map,C4=[10,20,50,100],T4=Bs.memo(function({page:l,pageSize:r,totalItems:c,jumpToPage:d,onPageChange:m,onPageSizeChange:h,onJumpToPageChange:f,onJumpToPage:p,onSelectionClear:g}){const N=Math.ceil(c/r),j=y=>{h(parseInt(y)),m(1),g?.()},b=y=>{y.key==="Enter"&&p()};return c===0?null:e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4 mt-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{htmlFor:"page-size-model",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(Pe,{value:r.toString(),onValueChange:j,children:[e.jsx(Be,{id:"page-size-model",className:"w-20",children:e.jsx(Fe,{})}),e.jsx(Ie,{children:C4.map(y=>e.jsx(W,{value:y.toString(),children:y},y))})]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["显示 ",(l-1)*r+1," 到"," ",Math.min(l*r,c)," 条,共 ",c," 条"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>m(1),disabled:l===1,className:"hidden sm:flex",children:e.jsx(kn,{className:"h-4 w-4"})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>m(Math.max(1,l-1)),disabled:l===1,children:[e.jsx(Pa,{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(ne,{type:"number",value:d,onChange:y=>f(y.target.value),onKeyDown:b,placeholder:l.toString(),className:"w-16 h-8 text-center",min:1,max:N}),e.jsx(_,{variant:"outline",size:"sm",onClick:p,disabled:!d,className:"h-8",children:"跳转"})]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>m(l+1),disabled:l>=N,children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(ra,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>m(N),disabled:l>=N,className:"hidden sm:flex",children:e.jsx(Cn,{className:"h-4 w-4"})})]})]})});function E4(a){const{models:l,taskConfig:r,debounceMs:c=2e3,onSavingChange:d,onUnsavedChange:m}=a,h=u.useRef(null),f=u.useRef(null),p=u.useRef(!0),g=u.useCallback(()=>{h.current&&(clearTimeout(h.current),h.current=null),f.current&&(clearTimeout(f.current),f.current=null)},[]),N=u.useCallback(y=>{const w={model_identifier:y.model_identifier,name:y.name,api_provider:y.api_provider,price_in:y.price_in??0,price_out:y.price_out??0,force_stream_mode:y.force_stream_mode??!1,extra_params:y.extra_params??{}};return y.temperature!=null&&(w.temperature=y.temperature),y.max_tokens!=null&&(w.max_tokens=y.max_tokens),w},[]),j=u.useCallback(async y=>{try{d?.(!0);const w=y.map(N);await Wm("models",w),m?.(!1)}catch(w){console.error("自动保存模型列表失败:",w),m?.(!0)}finally{d?.(!1)}},[d,m,N]),b=u.useCallback(async y=>{try{d?.(!0),await Wm("model_task_config",y),m?.(!1)}catch(w){console.error("自动保存任务配置失败:",w),m?.(!0)}finally{d?.(!1)}},[d,m]);return u.useEffect(()=>{if(!p.current)return m?.(!0),h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{j(l)},c),()=>{h.current&&clearTimeout(h.current)}},[l,j,c,m]),u.useEffect(()=>{if(!(p.current||!r))return m?.(!0),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>{b(r)},c),()=>{f.current&&clearTimeout(f.current)}},[r,b,c,m]),u.useEffect(()=>()=>{g()},[g]),{clearTimers:g,initialLoadRef:p}}function M4(a={}){const{onCloseEditDialog:l}=a,r=ha(),{registerTour:c,startTour:d,state:m,goToStep:h}=Ex(),f=u.useRef(m.stepIndex);return u.useEffect(()=>{c(gl,aN)},[c]),u.useEffect(()=>{if(m.activeTourId===gl&&m.isRunning){const g=lN[m.stepIndex];g&&!window.location.pathname.endsWith(g.replace("/config/",""))&&r({to:g})}},[m.stepIndex,m.activeTourId,m.isRunning,r]),u.useEffect(()=>{if(m.activeTourId===gl&&m.isRunning){const g=f.current,N=m.stepIndex;g>=12&&g<=17&&N<12&&l?.(),f.current=N}},[m.stepIndex,m.activeTourId,m.isRunning,l]),u.useEffect(()=>{if(m.activeTourId!==gl||!m.isRunning)return;const g=N=>{const j=N.target,b=m.stepIndex;b===2&&j.closest('[data-tour="add-provider-button"]')?setTimeout(()=>h(3),300):b===9&&j.closest('[data-tour="provider-cancel-button"]')?setTimeout(()=>h(10),300):b===11&&j.closest('[data-tour="add-model-button"]')?setTimeout(()=>h(12),300):b===17&&j.closest('[data-tour="model-cancel-button"]')?setTimeout(()=>h(18),300):b===18&&j.closest('[data-tour="tasks-tab-trigger"]')&&setTimeout(()=>h(19),300)};return document.addEventListener("click",g,!0),()=>document.removeEventListener("click",g,!0)},[m,h]),{startTour:u.useCallback(()=>{d(gl)},[d]),isRunning:m.isRunning&&m.activeTourId===gl,stepIndex:m.stepIndex}}function A4(a){const{getProviderConfig:l}=a,[r,c]=u.useState([]),[d,m]=u.useState(!1),[h,f]=u.useState(null),[p,g]=u.useState(null),N=u.useCallback(()=>{c([]),f(null),g(null)},[]),j=u.useCallback(async(b,y=!1)=>{const w=l(b);if(!w?.base_url){c([]),g(null),f('提供商配置不完整,请先在"模型提供商配置"中配置');return}if(!w.api_key){c([]),g(null),f('该提供商未配置 API Key,请先在"模型提供商配置"中填写');return}const z=n4(w.base_url);if(g(z),!z?.modelFetcher){c([]),f(null);return}const M=`${b}:${w.base_url}`,S=Zg.get(M);if(!y&&S&&Date.now()-S.timestampE(!1)}),{clearTimers:V,initialLoadRef:Ke}=E4({models:a,taskConfig:p,onSavingChange:z,onUnsavedChange:S}),He=u.useCallback((ae,oe)=>{if(!ae)return;const qe=new Set(oe.map(Ca=>Ca.name)),Ys=[],Ps=[],vt=[{key:"utils",label:"工具模型"},{key:"tool_use",label:"工具调用模型"},{key:"replyer",label:"回复模型"},{key:"planner",label:"规划器模型"},{key:"vlm",label:"视觉模型"},{key:"voice",label:"语音模型"},{key:"embedding",label:"嵌入模型"},{key:"lpmm_entity_extract",label:"LPMM实体抽取"},{key:"lpmm_rdf_build",label:"LPMM关系构建"}];for(const{key:Ca,label:ll}of vt){const ml=ae[Ca];if(!ml)continue;if(!ml.model_list||ml.model_list.length===0){Ps.push(ll);continue}const rr=ml.model_list.filter(Ql=>!qe.has(Ql));rr.length>0&&Ys.push({taskName:ll,invalidModels:rr})}le(Ys),xe(Ps)},[]),Je=u.useCallback(async()=>{try{j(!0);const ae=await Nn(),oe=ae.models||[];l(oe),f(oe.map(vt=>vt.name));const qe=ae.api_providers||[];c(qe.map(vt=>vt.name)),m(qe);const Ys=ae.model_task_config||null;g(Ys),He(Ys,oe);const Ps=Ys?.embedding?.model_list||[];J.current=[...Ps],S(!1),Ke.current=!1}catch(ae){console.error("加载配置失败:",ae)}finally{j(!1)}},[Ke,He]);u.useEffect(()=>{Je()},[Je]);const Es=u.useCallback(ae=>d.find(oe=>oe.name===ae),[d]),{availableModels:ms,fetchingModels:Ms,modelFetchError:We,matchedTemplate:Cs,fetchModelsForProvider:rs,clearModels:is}=A4({getProviderConfig:Es});u.useEffect(()=>{F&&C?.api_provider&&rs(C.api_provider)},[F,C?.api_provider,rs]);const ys=async()=>{await Ct()},rt=u.useCallback(()=>{if(!p)return;const ae=new Set(a.map(Ys=>Ys.name)),oe={...p},qe=Object.keys(oe);for(const Ys of qe){const Ps=oe[Ys];Ps&&Ps.model_list&&(Ps.model_list=Ps.model_list.filter(vt=>ae.has(vt)))}g(oe),le([]),Ts({title:"清理完成",description:"已删除所有无效的模型引用"})},[p,a,Ts]),jt=ae=>{const oe={model_identifier:ae.model_identifier,name:ae.name,api_provider:ae.api_provider,price_in:ae.price_in??0,price_out:ae.price_out??0,force_stream_mode:ae.force_stream_mode??!1,extra_params:ae.extra_params??{}};return ae.temperature!=null&&(oe.temperature=ae.temperature),ae.max_tokens!=null&&(oe.max_tokens=ae.max_tokens),oe},Ae=async()=>{try{y(!0),V();const ae=await Nn();ae.models=a.map(jt),ae.model_task_config=p,await lc(ae),S(!1),Ts({title:"保存成功",description:"正在重启麦麦..."}),await ys()}catch(ae){console.error("保存配置失败:",ae),Ts({title:"保存失败",description:ae.message,variant:"destructive"}),y(!1)}},Qe=async()=>{try{y(!0),V();const ae=await Nn();ae.models=a.map(jt),ae.model_task_config=p,await lc(ae),S(!1),Ts({title:"保存成功",description:"模型配置已保存"}),await Je()}catch(ae){console.error("保存配置失败:",ae),Ts({title:"保存失败",description:ae.message,variant:"destructive"})}finally{y(!1)}},As=(ae,oe)=>{ds({}),R(ae||{model_identifier:"",name:"",api_provider:r[0]||"",price_in:0,price_out:0,temperature:null,max_tokens:null,force_stream_mode:!1,extra_params:{}}),O(oe),E(!0)},mt=()=>{if(!C)return;const ae={};if(C.name?.trim()?a.some((vt,Ca)=>H!==null&&Ca===H?!1:vt.name.trim().toLowerCase()===C.name.trim().toLowerCase())&&(ae.name="模型名称已存在,请使用其他名称"):ae.name="请输入模型名称",C.api_provider?.trim()||(ae.api_provider="请选择 API 提供商"),C.model_identifier?.trim()||(ae.model_identifier="请输入模型标识符"),Object.keys(ae).length>0){ds(ae);return}ds({});const oe={model_identifier:C.model_identifier,name:C.name,api_provider:C.api_provider,price_in:C.price_in??0,price_out:C.price_out??0,force_stream_mode:C.force_stream_mode??!1,extra_params:C.extra_params??{}};C.temperature!=null&&(oe.temperature=C.temperature),C.max_tokens!=null&&(oe.max_tokens=C.max_tokens);let qe,Ys=null;if(H!==null?(Ys=a[H].name,qe=[...a],qe[H]=oe):qe=[...a,oe],l(qe),f(qe.map(Ps=>Ps.name)),Ys&&Ys!==oe.name&&p){const Ps=vt=>vt.map(Ca=>Ca===Ys?oe.name:Ca);g({...p,utils:{...p.utils,model_list:Ps(p.utils?.model_list||[])},tool_use:{...p.tool_use,model_list:Ps(p.tool_use?.model_list||[])},replyer:{...p.replyer,model_list:Ps(p.replyer?.model_list||[])},planner:{...p.planner,model_list:Ps(p.planner?.model_list||[])},vlm:{...p.vlm,model_list:Ps(p.vlm?.model_list||[])},voice:{...p.voice,model_list:Ps(p.voice?.model_list||[])},embedding:{...p.embedding,model_list:Ps(p.embedding?.model_list||[])},lpmm_entity_extract:{...p.lpmm_entity_extract,model_list:Ps(p.lpmm_entity_extract?.model_list||[])},lpmm_rdf_build:{...p.lpmm_rdf_build,model_list:Ps(p.lpmm_rdf_build?.model_list||[])}})}E(!1),R(null),O(null),Ts({title:H!==null?"模型已更新":"模型已添加",description:'配置将在 2 秒后自动保存,或点击右上角"保存配置"按钮立即保存'})},Ht=ae=>{if(!ae&&C){const oe={...C,price_in:C.price_in??0,price_out:C.price_out??0};R(oe)}E(ae)},ca=ae=>{ce(ae),Ne(!0)},Fa=()=>{if(je!==null){const ae=a.filter((oe,qe)=>qe!==je);l(ae),f(ae.map(oe=>oe.name)),He(p,ae),Ts({title:"删除成功",description:'配置将在 2 秒后自动保存,或点击右上角"保存配置"按钮立即保存'})}Ne(!1),ce(null)},Xt=ae=>{const oe=new Set(D);oe.has(ae)?oe.delete(ae):oe.add(ae),Q(oe)},te=()=>{if(D.size===es.length)Q(new Set);else{const ae=es.map((oe,qe)=>a.findIndex(Ys=>Ys===es[qe]));Q(new Set(ae))}},_e=()=>{if(D.size===0){Ts({title:"提示",description:"请先选择要删除的模型",variant:"default"});return}ue(!0)},U=()=>{const ae=D.size,oe=a.filter((qe,Ys)=>!D.has(Ys));l(oe),f(oe.map(qe=>qe.name)),He(p,oe),Q(new Set),ue(!1),Ts({title:"批量删除成功",description:`已删除 ${ae} 个模型,配置将在 2 秒后自动保存`})},Se=(ae,oe,qe)=>{if(!p)return;if(ae==="embedding"&&oe==="model_list"&&Array.isArray(qe)){const Ps=J.current,vt=qe;if((Ps.length!==vt.length||Ps.some(ll=>!vt.includes(ll))||vt.some(ll=>!Ps.includes(ll)))&&Ps.length>0){Z.current={field:oe,value:qe},cs(!0);return}}const Ys={...p,[ae]:{...p[ae],[oe]:qe}};g(Ys),He(Ys,a),ae==="embedding"&&oe==="model_list"&&Array.isArray(qe)&&(J.current=[...qe])},as=()=>{if(!p||!Z.current)return;const{field:ae,value:oe}=Z.current,qe={...p,embedding:{...p.embedding,[ae]:oe}};g(qe),He(qe,a),ae==="model_list"&&Array.isArray(oe)&&(J.current=[...oe]),Z.current=null,cs(!1),Ts({title:"嵌入模型已更新",description:"建议重新生成知识库向量以确保最佳匹配精度"})},us=()=>{Z.current=null,cs(!1)},es=a.filter(ae=>{if(!ge)return!0;const oe=ge.toLowerCase();return ae.name.toLowerCase().includes(oe)||ae.model_identifier.toLowerCase().includes(oe)||ae.api_provider.toLowerCase().includes(oe)}),Tt=Math.ceil(es.length/fe),$s=es.slice((Y-1)*fe,Y*fe),pa=()=>{const ae=parseInt(G);ae>=1&&ae<=Tt&&(we(ae),$(""))},oa=ae=>p?[p.utils?.model_list||[],p.tool_use?.model_list||[],p.replyer?.model_list||[],p.planner?.model_list||[],p.vlm?.model_list||[],p.voice?.model_list||[],p.embedding?.model_list||[],p.lpmm_entity_extract?.model_list||[],p.lpmm_rdf_build?.model_list||[]].some(qe=>qe.includes(ae)):!1;return N?e.jsx(ts,{className:"h-full",children:e.jsx("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("p",{className:"text-muted-foreground",children:"加载中..."})})})}):e.jsx(ts,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"模型管理与分配"}),e.jsx("p",{className:"text-muted-foreground mt-1 sm:mt-2 text-sm sm:text-base",children:"添加模型并为模型分配功能"})]}),e.jsxs("div",{className:"flex gap-2 w-full sm:w-auto",children:[e.jsx(b4,{trigger:e.jsxs(_,{variant:"outline",size:"sm",className:"flex-1 sm:flex-none",children:[e.jsx(mv,{className:"mr-2 h-4 w-4"}),"分享配置"]})}),e.jsxs(_,{onClick:Qe,disabled:b||w||!M||ia,size:"sm",variant:"outline",className:"flex-1 sm:flex-none sm:min-w-[120px]",children:[e.jsx(gc,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),b?"保存中...":w?"自动保存中...":M?"保存配置":"已保存"]}),e.jsxs(bs,{children:[e.jsx(wt,{asChild:!0,children:e.jsxs(_,{disabled:b||w||ia,size:"sm",className:"flex-1 sm:flex-none sm:min-w-[120px]",children:[e.jsx(pc,{className:"mr-2 h-4 w-4"}),ia?"重启中...":M?"保存并重启":"重启麦麦"]})}),e.jsxs(xs,{children:[e.jsxs(hs,{children:[e.jsx(ps,{children:"确认重启麦麦?"}),e.jsx(gs,{asChild:!0,children:e.jsx("div",{children:e.jsx("p",{children:M?"当前有未保存的配置更改。点击确认将先保存配置,然后重启麦麦使新配置生效。重启过程中麦麦将暂时离线。":"即将重启麦麦主程序。重启过程中麦麦将暂时离线,配置将在重启后生效。"})})})]}),e.jsxs(fs,{children:[e.jsx(vs,{children:"取消"}),e.jsx(js,{onClick:M?Ae:ys,children:M?"保存并重启":"确认重启"})]})]})]})]})]}),e.jsxs(ht,{children:[e.jsx(Yt,{className:"h-4 w-4"}),e.jsxs(ft,{children:["配置更新后需要",e.jsx("strong",{children:"重启麦麦"}),'才能生效。你可以点击右上角的"保存并重启"按钮一键完成保存和重启。']})]}),Le.length>0&&e.jsxs(ht,{variant:"destructive",children:[e.jsx(Lt,{className:"h-4 w-4"}),e.jsxs(ft,{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("strong",{children:"检测到无效的模型引用"}),e.jsx("div",{className:"mt-2 space-y-1",children:Le.map(({taskName:ae,invalidModels:oe})=>e.jsxs("div",{className:"text-sm",children:[e.jsx("strong",{children:ae})," 引用了不存在的模型: ",oe.join(", ")]},ae))})]}),e.jsx(_,{variant:"outline",size:"sm",className:"shrink-0 bg-background hover:bg-accent",onClick:rt,children:"一键清理"})]})]}),De.length>0&&e.jsxs(ht,{variant:"default",className:"border-yellow-500/50 bg-yellow-500/10",children:[e.jsx(Lt,{className:"h-4 w-4 text-yellow-600"}),e.jsxs(ft,{children:[e.jsx("strong",{className:"text-yellow-600",children:"以下任务未配置模型"}),e.jsxs("div",{className:"mt-2 text-sm",children:[De.join("、")," 还未分配模型,这些功能将无法正常工作。"]})]})]}),e.jsxs(ht,{className:"hidden lg:flex border-primary/30 bg-primary/5 cursor-pointer hover:bg-primary/10 transition-colors",onClick:ut,children:[e.jsx(U1,{className:"h-4 w-4 text-primary"}),e.jsxs(ft,{className:"flex items-center justify-between",children:[e.jsxs("span",{children:[e.jsx("strong",{className:"text-primary",children:"新手引导:"}),"不知道如何配置模型?点击这里开始学习如何为麦麦的组件分配模型。"]}),e.jsx(_,{variant:"outline",size:"sm",className:"ml-4 shrink-0",children:"开始引导"})]})]}),e.jsxs(Jt,{defaultValue:"models",className:"w-full",children:[e.jsxs(Gt,{className:"grid w-full max-w-full sm:max-w-md grid-cols-2",children:[e.jsx(Xe,{value:"models",children:"添加模型"}),e.jsx(Xe,{value:"tasks","data-tour":"tasks-tab-trigger",children:"为模型分配功能"})]}),e.jsxs(Ss,{value:"models",className:"space-y-4 mt-0",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center gap-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"配置可用的模型列表"}),e.jsxs("div",{className:"flex gap-2 w-full sm:w-auto",children:[D.size>0&&e.jsxs(_,{onClick:_e,size:"sm",variant:"destructive",className:"w-full sm:w-auto",children:[e.jsx(os,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),"批量删除 (",D.size,")"]}),e.jsxs(_,{onClick:()=>As(null,null),size:"sm",variant:"outline",className:"w-full sm:w-auto","data-tour":"add-model-button",children:[e.jsx(Xs,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),"添加模型"]})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center gap-2",children:[e.jsxs("div",{className:"relative w-full sm:flex-1 sm:max-w-sm",children:[e.jsx($t,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ne,{placeholder:"搜索模型名称、标识符或提供商...",value:ge,onChange:ae=>pe(ae.target.value),className:"pl-9"})]}),ge&&e.jsxs("p",{className:"text-sm text-muted-foreground whitespace-nowrap",children:["找到 ",es.length," 个结果"]})]}),e.jsx(_4,{paginatedModels:$s,allModels:a,onEdit:As,onDelete:ca,isModelUsed:oa,searchQuery:ge}),e.jsx(S4,{paginatedModels:$s,allModels:a,filteredModels:es,selectedModels:D,onEdit:As,onDelete:ca,onToggleSelection:Xt,onToggleSelectAll:te,isModelUsed:oa,searchQuery:ge}),e.jsx(T4,{page:Y,pageSize:fe,totalItems:es.length,jumpToPage:G,onPageChange:we,onPageSizeChange:Ee,onJumpToPageChange:$,onJumpToPage:pa,onSelectionClear:()=>Q(new Set)})]}),e.jsxs(Ss,{value:"tasks",className:"space-y-6 mt-0",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"为不同的任务配置使用的模型和参数"}),p&&e.jsxs("div",{className:"grid gap-4 sm:gap-6",children:[e.jsx(Ul,{title:"组件模型 (utils)",description:"用于表情包、取名、关系、情绪变化等组件",taskConfig:p.utils,modelNames:h,onChange:(ae,oe)=>Se("utils",ae,oe),dataTour:"task-model-select"}),e.jsx(Ul,{title:"工具调用模型 (tool_use)",description:"需要使用支持工具调用的模型",taskConfig:p.tool_use,modelNames:h,onChange:(ae,oe)=>Se("tool_use",ae,oe)}),e.jsx(Ul,{title:"首要回复模型 (replyer)",description:"用于表达器和表达方式学习",taskConfig:p.replyer,modelNames:h,onChange:(ae,oe)=>Se("replyer",ae,oe)}),e.jsx(Ul,{title:"决策模型 (planner)",description:"负责决定麦麦该什么时候回复",taskConfig:p.planner,modelNames:h,onChange:(ae,oe)=>Se("planner",ae,oe)}),e.jsx(Ul,{title:"图像识别模型 (vlm)",description:"视觉语言模型",taskConfig:p.vlm,modelNames:h,onChange:(ae,oe)=>Se("vlm",ae,oe),hideTemperature:!0}),e.jsx(Ul,{title:"语音识别模型 (voice)",description:"语音转文字",taskConfig:p.voice,modelNames:h,onChange:(ae,oe)=>Se("voice",ae,oe),hideTemperature:!0,hideMaxTokens:!0}),e.jsx(Ul,{title:"嵌入模型 (embedding)",description:"用于向量化",taskConfig:p.embedding,modelNames:h,onChange:(ae,oe)=>Se("embedding",ae,oe),hideTemperature:!0,hideMaxTokens:!0}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"LPMM 知识库模型"}),e.jsx(Ul,{title:"实体提取模型 (lpmm_entity_extract)",description:"从文本中提取实体",taskConfig:p.lpmm_entity_extract,modelNames:h,onChange:(ae,oe)=>Se("lpmm_entity_extract",ae,oe)}),e.jsx(Ul,{title:"RDF 构建模型 (lpmm_rdf_build)",description:"构建知识图谱",taskConfig:p.lpmm_rdf_build,modelNames:h,onChange:(ae,oe)=>Se("lpmm_rdf_build",ae,oe)})]})]})]})]}),e.jsx(Qs,{open:F,onOpenChange:Ht,children:e.jsxs(Hs,{className:"max-w-[95vw] sm:max-w-2xl max-h-[90vh] overflow-y-auto","data-tour":"model-dialog",preventOutsideClose:Is,children:[e.jsxs(qs,{children:[e.jsx(Vs,{children:H!==null?"编辑模型":"添加模型"}),e.jsx(at,{children:"配置模型的基本信息和参数"})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid gap-2","data-tour":"model-name-input",children:[e.jsx(T,{htmlFor:"model_name",className:Me.name?"text-destructive":"",children:"模型名称 *"}),e.jsx(ne,{id:"model_name",value:C?.name||"",onChange:ae=>{R(oe=>oe?{...oe,name:ae.target.value}:null),Me.name&&ds(oe=>({...oe,name:void 0}))},placeholder:"例如: qwen3-30b",className:Me.name?"border-destructive focus-visible:ring-destructive":""}),Me.name?e.jsx("p",{className:"text-xs text-destructive",children:Me.name}):e.jsx("p",{className:"text-xs text-muted-foreground",children:"用于在任务配置中引用此模型"})]}),e.jsxs("div",{className:"grid gap-2","data-tour":"model-provider-select",children:[e.jsx(T,{htmlFor:"api_provider",className:Me.api_provider?"text-destructive":"",children:"API 提供商 *"}),e.jsxs(Pe,{value:C?.api_provider||"",onValueChange:ae=>{R(oe=>oe?{...oe,api_provider:ae}:null),is(),Me.api_provider&&ds(oe=>({...oe,api_provider:void 0}))},children:[e.jsx(Be,{id:"api_provider",className:Me.api_provider?"border-destructive focus-visible:ring-destructive":"",children:e.jsx(Fe,{placeholder:"选择提供商"})}),e.jsx(Ie,{children:r.map(ae=>e.jsx(W,{value:ae,children:ae},ae))})]}),Me.api_provider&&e.jsx("p",{className:"text-xs text-destructive",children:Me.api_provider})]}),e.jsxs("div",{className:"grid gap-2","data-tour":"model-identifier-input",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{htmlFor:"model_identifier",className:Me.model_identifier?"text-destructive":"",children:"模型标识符 *"}),Cs?.modelFetcher&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ce,{variant:"secondary",className:"text-xs",children:Cs.display_name}),e.jsx(_,{variant:"ghost",size:"sm",className:"h-6 px-2",onClick:()=>C?.api_provider&&rs(C.api_provider,!0),disabled:Ms,children:Ms?e.jsx(Fs,{className:"h-3 w-3 animate-spin"}):e.jsx(dt,{className:"h-3 w-3"})})]})]}),Cs?.modelFetcher?e.jsxs(cl,{open:Re,onOpenChange:se,children:[e.jsx(ol,{asChild:!0,children:e.jsxs(_,{variant:"outline",role:"combobox","aria-expanded":Re,className:"w-full justify-between font-normal",disabled:Ms||!!We,children:[Ms?e.jsxs("span",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(Fs,{className:"h-4 w-4 animate-spin"}),"正在获取模型列表..."]}):We?e.jsx("span",{className:"text-muted-foreground text-sm",children:"点击下方输入框手动填写"}):C?.model_identifier?e.jsx("span",{className:"truncate",children:C.model_identifier}):e.jsx("span",{className:"text-muted-foreground",children:"搜索或选择模型..."}),e.jsx(mx,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(tl,{className:"p-0",align:"start",style:{width:"var(--radix-popover-trigger-width)"},children:e.jsxs(md,{children:[e.jsx(xd,{placeholder:"搜索模型..."}),e.jsx(ts,{className:"h-[300px]",children:e.jsxs(hd,{className:"max-h-none overflow-visible",children:[e.jsx(fd,{children:We?e.jsxs("div",{className:"py-4 px-2 text-center space-y-2",children:[e.jsx("p",{className:"text-sm text-destructive",children:We}),!We.includes("API Key")&&e.jsx(_,{variant:"link",size:"sm",onClick:()=>C?.api_provider&&rs(C.api_provider,!0),children:"重试"})]}):"未找到匹配的模型"}),e.jsx(uc,{heading:"可用模型",children:ms.map(ae=>e.jsxs(mc,{value:ae.id,onSelect:()=>{R(oe=>oe?{...oe,model_identifier:ae.id}:null),se(!1)},children:[e.jsx(Ot,{className:`mr-2 h-4 w-4 ${C?.model_identifier===ae.id?"opacity-100":"opacity-0"}`}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:ae.id}),ae.name!==ae.id&&e.jsx("span",{className:"text-xs text-muted-foreground",children:ae.name})]})]},ae.id))}),e.jsx(uc,{heading:"手动输入",children:e.jsxs(mc,{value:"__manual_input__",onSelect:()=>{se(!1)},children:[e.jsx(Zn,{className:"mr-2 h-4 w-4"}),"手动输入模型标识符..."]})})]})})]})})]}):e.jsx(ne,{id:"model_identifier",value:C?.model_identifier||"",onChange:ae=>{R(oe=>oe?{...oe,model_identifier:ae.target.value}:null),Me.model_identifier&&ds(oe=>({...oe,model_identifier:void 0}))},placeholder:"Qwen/Qwen3-30B-A3B-Instruct-2507",className:Me.model_identifier?"border-destructive focus-visible:ring-destructive":""}),Me.model_identifier&&e.jsx("p",{className:"text-xs text-destructive",children:Me.model_identifier}),We&&Cs?.modelFetcher&&!Me.model_identifier&&e.jsxs(ht,{variant:"destructive",className:"mt-2 py-2",children:[e.jsx(Yt,{className:"h-4 w-4"}),e.jsx(ft,{className:"text-xs",children:We})]}),Cs?.modelFetcher&&e.jsx(ne,{value:C?.model_identifier||"",onChange:ae=>{R(oe=>oe?{...oe,model_identifier:ae.target.value}:null),Me.model_identifier&&ds(oe=>({...oe,model_identifier:void 0}))},placeholder:"或手动输入模型标识符",className:`mt-2 ${Me.model_identifier?"border-destructive focus-visible:ring-destructive":""}`}),!Me.model_identifier&&e.jsx("p",{className:"text-xs text-muted-foreground",children:We?'请手动输入模型标识符,或前往"模型提供商配置"检查 API Key':Cs?.modelFetcher?`已识别为 ${Cs.display_name},支持自动获取模型列表`:"API 提供商提供的模型 ID"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"price_in",children:"输入价格 (¥/M token)"}),e.jsx(ne,{id:"price_in",type:"number",step:"0.1",min:"0",value:C?.price_in??"",onChange:ae=>{const oe=ae.target.value===""?null:parseFloat(ae.target.value);R(qe=>qe?{...qe,price_in:oe}:null)},placeholder:"默认: 0"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"price_out",children:"输出价格 (¥/M token)"}),e.jsx(ne,{id:"price_out",type:"number",step:"0.1",min:"0",value:C?.price_out??"",onChange:ae=>{const oe=ae.target.value===""?null:parseFloat(ae.target.value);R(qe=>qe?{...qe,price_out:oe}:null)},placeholder:"默认: 0"})]})]}),e.jsxs("div",{className:"rounded-lg border p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(T,{htmlFor:"enable_model_temperature",className:"cursor-pointer",children:"自定义模型温度"}),e.jsx(Bl,{content:e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-medium",children:"什么是温度(Temperature)?"}),e.jsx("p",{children:"温度控制模型输出的随机性和创造性:"}),e.jsxs("ul",{className:"list-disc list-inside space-y-1 text-xs",children:[e.jsxs("li",{children:[e.jsx("strong",{children:"低温度(0.1-0.3)"}),":更确定、更保守的输出,适合事实性任务"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"中温度(0.5-0.7)"}),":平衡创造性与可控性"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"高温度(0.8-1.0)"}),":更有创意、更多样化的输出"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"极高温度(1.0-2.0)"}),":极度随机,可能产生不可预测的结果"]})]})]}),side:"right",maxWidth:"400px"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"启用后将覆盖「为模型分配功能」中的任务温度配置"})]}),e.jsx(Ge,{id:"enable_model_temperature",checked:C?.temperature!=null,onCheckedChange:ae=>{R(ae?oe=>oe?{...oe,temperature:.5}:null:oe=>oe?{...oe,temperature:null}:null)}})]}),C?.temperature!=null&&e.jsxs("div",{className:"space-y-3 pt-2 border-t",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(T,{className:"text-sm",children:"温度值"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ne,{type:"number",value:C.temperature,onChange:ae=>{const oe=parseFloat(ae.target.value);!isNaN(oe)&&oe>=0&&oe<=2&&R(qe=>qe?{...qe,temperature:oe}:null)},onBlur:ae=>{const oe=parseFloat(ae.target.value);isNaN(oe)||oe<0?R(qe=>qe?{...qe,temperature:0}:null):oe>2&&R(qe=>qe?{...qe,temperature:2}:null)},step:.01,min:0,max:2,className:"w-20 h-8 text-sm text-right tabular-nums"}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>K(!A),className:"h-8 px-2",title:A?"切换到基础模式 (0-1)":"解锁高级范围 (0-2)",children:A?e.jsx($1,{className:"h-4 w-4"}):e.jsx(Jm,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:"0"}),e.jsx(el,{value:[C.temperature],onValueChange:ae=>R(oe=>oe?{...oe,temperature:ae[0]}:null),min:0,max:A?2:1,step:A?.05:.1,className:"flex-1"}),e.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:A?"2":"1"})]}),A&&e.jsxs(ht,{className:"bg-amber-500/10 border-amber-500/20 [&>svg+div]:translate-y-0",children:[e.jsx(Lt,{className:"h-4 w-4 text-amber-500"}),e.jsx(ft,{className:"text-xs text-amber-600 dark:text-amber-400",children:"高级模式:温度 > 1 会产生更随机、更不可预测的输出,请谨慎使用"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:A?"较低(0.1-0.5)产生确定输出,中等(0.5-1.0)平衡创造性,较高(1.0-2.0)产生极度随机输出":"较低的温度(0.1-0.3)产生更确定的输出,较高的温度(0.7-1.0)产生更多样化的输出"})]})]}),e.jsxs("div",{className:"rounded-lg border p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(T,{htmlFor:"enable_model_max_tokens",className:"cursor-pointer",children:"自定义最大 Token"}),e.jsx(Bl,{content:e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-medium",children:"什么是最大 Token?"}),e.jsx("p",{children:"控制模型单次回复的最大长度。1 token ≈ 0.75 个英文单词或 0.5 个中文字符。"}),e.jsxs("ul",{className:"list-disc list-inside space-y-1 text-xs",children:[e.jsxs("li",{children:[e.jsx("strong",{children:"较小值(512-1024)"}),":简短回复,节省成本"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"中等值(2048-4096)"}),":正常对话长度"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"较大值(8192+)"}),":长文本生成,成本较高"]})]})]}),side:"right",maxWidth:"400px"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"启用后将覆盖「为模型分配功能」中的任务最大 Token 配置"})]}),e.jsx(Ge,{id:"enable_model_max_tokens",checked:C?.max_tokens!=null,onCheckedChange:ae=>{R(ae?oe=>oe?{...oe,max_tokens:2048}:null:oe=>oe?{...oe,max_tokens:null}:null)}})]}),C?.max_tokens!=null&&e.jsxs("div",{className:"space-y-2 pt-2 border-t",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{className:"text-sm",children:"最大 Token 数"}),e.jsx(ne,{type:"number",min:"1",max:"128000",value:C.max_tokens,onChange:ae=>{const oe=parseInt(ae.target.value);!isNaN(oe)&&oe>=1&&R(qe=>qe?{...qe,max_tokens:oe}:null)},className:"w-28 h-8 text-sm"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"限制模型单次输出的最大 token 数量,不同模型支持的上限不同"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ge,{id:"force_stream_mode",checked:C?.force_stream_mode||!1,onCheckedChange:ae=>R(oe=>oe?{...oe,force_stream_mode:ae}:null)}),e.jsx(T,{htmlFor:"force_stream_mode",className:"cursor-pointer",children:"强制流式输出模式"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{className:"text-sm font-medium",children:"额外参数"}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(_,{type:"button",variant:"outline",size:"sm",className:"flex-1 justify-start h-9",onClick:()=>L(!0),children:[e.jsx(Sn,{className:"h-4 w-4 mr-2"}),Object.keys(C?.extra_params||{}).length>0?e.jsxs("span",{children:["已配置 ",Object.keys(C?.extra_params||{}).length," 个参数"]}):e.jsx("span",{className:"text-muted-foreground",children:"未配置额外参数"})]})}),Object.keys(C?.extra_params||{}).length>0&&e.jsxs("div",{className:"text-xs text-muted-foreground px-1",children:[Object.keys(C?.extra_params||{}).slice(0,3).map(ae=>e.jsx("span",{className:"inline-block mr-2",children:e.jsx("code",{className:"px-1.5 py-0.5 bg-muted rounded",children:ae})},ae)),Object.keys(C?.extra_params||{}).length>3&&e.jsx("span",{children:"..."})]})]})]}),e.jsxs(gt,{children:[e.jsx(_,{variant:"outline",onClick:()=>E(!1),"data-tour":"model-cancel-button",children:"取消"}),e.jsx(_,{onClick:mt,"data-tour":"model-save-button",children:"保存"})]})]})}),e.jsx(bs,{open:me,onOpenChange:Ne,children:e.jsxs(xs,{children:[e.jsxs(hs,{children:[e.jsx(ps,{children:"确认删除"}),e.jsxs(gs,{children:['确定要删除模型 "',je!==null?a[je]?.name:"",'" 吗? 此操作无法撤销。']})]}),e.jsxs(fs,{children:[e.jsx(vs,{children:"取消"}),e.jsx(js,{onClick:Fa,children:"删除"})]})]})}),e.jsx(bs,{open:B,onOpenChange:ue,children:e.jsxs(xs,{children:[e.jsxs(hs,{children:[e.jsx(ps,{children:"确认批量删除"}),e.jsxs(gs,{children:["确定要删除选中的 ",D.size," 个模型吗? 此操作无法撤销。"]})]}),e.jsxs(fs,{children:[e.jsx(vs,{children:"取消"}),e.jsx(js,{onClick:U,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"批量删除"})]})]})}),e.jsx(bs,{open:$e,onOpenChange:cs,children:e.jsxs(xs,{children:[e.jsxs(hs,{children:[e.jsxs(ps,{className:"flex items-center gap-2",children:[e.jsx(Lt,{className:"h-5 w-5 text-amber-500"}),"更换嵌入模型警告"]}),e.jsx(gs,{asChild:!0,children:e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsxs("p",{children:[e.jsx("strong",{className:"text-foreground",children:"注意:"}),"更换嵌入模型可能会影响知识库的匹配精度!"]}),e.jsxs("ul",{className:"space-y-2 ml-4 list-disc text-muted-foreground",children:[e.jsx("li",{children:"不同的嵌入模型会产生不同的向量表示"}),e.jsx("li",{children:"这可能导致现有知识库的检索结果不准确"}),e.jsx("li",{children:"建议更换嵌入模型后重新生成所有知识库的向量"})]}),e.jsx("p",{className:"text-foreground font-medium",children:"确定要更换嵌入模型吗?"})]})})]}),e.jsxs(fs,{children:[e.jsx(vs,{onClick:us,children:"取消"}),e.jsx(js,{onClick:as,className:"bg-amber-600 hover:bg-amber-700",children:"确认更换"})]})]})}),e.jsx(u4,{open:X,onOpenChange:L,value:C?.extra_params||{},onChange:ae=>R(oe=>oe?{...oe,extra_params:ae}:null)}),e.jsx(nr,{})]})})}const xc=Mj,hc=Aw,fc=zw,pd="/api/webui/config";async function D4(){const l=await(await ke(`${pd}/adapter-config/path`)).json();return!l.success||!l.path?null:{path:l.path,lastModified:l.lastModified}}async function Wg(a){const r=await(await ke(`${pd}/adapter-config/path`,{method:"POST",headers:Zs(),body:JSON.stringify({path:a})})).json();if(!r.success)throw new Error(r.message||"保存路径失败")}async function ej(a){const r=await(await ke(`${pd}/adapter-config?path=${encodeURIComponent(a)}`)).json();if(!r.success)throw new Error("读取配置文件失败");return r.content}async function sj(a,l){const c=await(await ke(`${pd}/adapter-config`,{method:"POST",headers:Zs(),body:JSON.stringify({path:a,content:l})})).json();if(!c.success)throw new Error(c.message||"保存配置失败")}const kt={inner:{version:"0.1.2"},nickname:{nickname:""},napcat_server:{host:"localhost",port:8095,token:"",heartbeat_interval:30},maibot_server:{host:"localhost",port:8e3},chat:{group_list_type:"whitelist",group_list:[],private_list_type:"whitelist",private_list:[],ban_user_id:[],ban_qq_bot:!1,enable_poke:!0},voice:{use_tts:!1},forward:{image_threshold:30},debug:{level:"INFO"}},Fm={oneclick:{name:"一键包",description:"使用一键包部署的适配器配置",path:"../MaiBot-Napcat-Adapter/config.toml",icon:xa},docker:{name:"Docker",description:"Docker Compose 部署的适配器配置",path:"/MaiMBot/adapters-config/config.toml",icon:B1}};function Hm(a){try{const l=_x(a);return{inner:{...kt.inner,...l.inner},nickname:{...kt.nickname,...l.nickname},napcat_server:{...kt.napcat_server,...l.napcat_server},maibot_server:{...kt.maibot_server,...l.maibot_server},chat:{...kt.chat,...l.chat},voice:{...kt.voice,...l.voice},forward:{...kt.forward,...l.forward},debug:{...kt.debug,...l.debug}}}catch(l){throw console.error("TOML 解析失败:",l),new Error(`无法解析 TOML 文件: ${l instanceof Error?l.message:"未知错误"}`)}}function qm(a){try{const l=(d,m)=>d===""||d===null||d===void 0?m:d,r={inner:{version:l(a.inner.version,kt.inner.version)},nickname:{nickname:l(a.nickname.nickname,kt.nickname.nickname)},napcat_server:{host:l(a.napcat_server.host,kt.napcat_server.host),port:l(a.napcat_server.port||0,kt.napcat_server.port),token:l(a.napcat_server.token,kt.napcat_server.token),heartbeat_interval:l(a.napcat_server.heartbeat_interval||0,kt.napcat_server.heartbeat_interval)},maibot_server:{host:l(a.maibot_server.host,kt.maibot_server.host),port:l(a.maibot_server.port||0,kt.maibot_server.port)},chat:{group_list_type:l(a.chat.group_list_type,kt.chat.group_list_type),group_list:a.chat.group_list||[],private_list_type:l(a.chat.private_list_type,kt.chat.private_list_type),private_list:a.chat.private_list||[],ban_user_id:a.chat.ban_user_id||[],ban_qq_bot:a.chat.ban_qq_bot??kt.chat.ban_qq_bot,enable_poke:a.chat.enable_poke??kt.chat.enable_poke},voice:{use_tts:a.voice.use_tts??kt.voice.use_tts},forward:{image_threshold:l(a.forward.image_threshold||0,kt.forward.image_threshold)},debug:{level:l(a.debug.level,kt.debug.level)}};let c=GS(r);return c=O4(c),c}catch(l){throw console.error("TOML 生成失败:",l),new Error(`无法生成 TOML 文件: ${l instanceof Error?l.message:"未知错误"}`)}}function O4(a){const l=a.split(` +`),d}async function g4(a,l,r,c){const d=await ke("/api/webui/config/model");if(!d.ok)throw new Error("获取当前模型配置失败");const m=await d.json(),h=m.config||m;if(l.apply_providers){const p=l.selected_providers?a.providers.filter(g=>l.selected_providers.includes(g.name)):a.providers;for(const g of p){if(r[g.name])continue;const N=c[g.name];if(!N)throw new Error(`提供商 "${g.name}" 缺少 API Key`);const j={...g,api_key:N},b=h.api_providers.findIndex(y=>y.name===g.name);b>=0?h.api_providers[b]=j:h.api_providers.push(j)}}if(l.apply_models){const p=l.selected_models?a.models.filter(g=>l.selected_models.includes(g.name)):a.models;for(const g of p){const N=r[g.api_provider]||g.api_provider,j={...g,api_provider:N},b=h.models.findIndex(y=>y.name===g.name);b>=0?h.models[b]=j:h.models.push(j)}}if(l.apply_task_config){const p=l.selected_tasks||Object.keys(a.task_config);for(const g of p){const N=a.task_config[g];if(!N)continue;const j=new Set(l.selected_models||a.models.map(w=>w.name)),b=N.model_list.filter(w=>j.has(w));if(b.length===0)continue;const y={...N,model_list:b};if(l.task_mode==="replace")h.model_task_config[g]=y;else{const w=h.model_task_config[g];if(w){const z=[...new Set([...w.model_list,...b])];h.model_task_config[g]={...w,model_list:z}}else h.model_task_config[g]=y}}}if(!(await ke("/api/webui/config/model",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(h)})).ok)throw new Error("保存配置失败")}async function j4(a){const l=await ke("/api/webui/config/model");if(!l.ok)throw new Error("获取当前模型配置失败");const r=await l.json();if(!r.success||!r.config)throw new Error("获取配置失败");const c=r.config;let d=(c.api_providers||[]).map(g=>({name:g.name,base_url:g.base_url,client_type:g.client_type,max_retry:g.max_retry,timeout:g.timeout,retry_interval:g.retry_interval}));a.selectedProviders&&(d=d.filter(g=>a.selectedProviders.includes(g.name)));let m=c.models||[];a.selectedModels&&(m=m.filter(g=>a.selectedModels.includes(g.name)));const h={},f=c.model_task_config||{},p=a.selectedTasks||Object.keys(f);for(const g of p)f[g]&&(h[g]=f[g]);return{providers:d,models:m,task_config:h}}function Pm(a){try{const l=new URL(a);return`${l.protocol}//${l.host}${l.pathname}`.replace(/\/$/,"").toLowerCase()}catch{return a.toLowerCase().replace(/\/$/,"")}}function cN(){const a="maibot_pack_user_id";let l=localStorage.getItem(a);return l||(l="pack_user_"+Math.random().toString(36).substring(2,15),localStorage.setItem(a,l)),l}const v4={utils:"通用工具",utils_small:"轻量工具",tool_use:"工具调用",replyer:"回复生成",planner:"规划推理",vlm:"视觉模型",voice:"语音处理",embedding:"向量嵌入",lpmm_entity_extract:"实体提取",lpmm_rdf_build:"RDF构建",tts_instruct:"TTS指令",lpmm_qa:"问答模型"},N4=["官方推荐","性价比","高性能","免费模型","国内可用","海外模型","OpenAI","Claude","Gemini","国产模型","多模态","轻量级"];function b4({trigger:a}){const[l,r]=u.useState(!1),[c,d]=u.useState(1),[m,h]=u.useState(!1),[f,p]=u.useState(!1),[g,N]=u.useState([]),[j,b]=u.useState([]),[y,w]=u.useState({}),[z,M]=u.useState(new Set),[S,F]=u.useState(new Set),[E,C]=u.useState(new Set),[R,H]=u.useState(""),[O,X]=u.useState(""),[L,me]=u.useState(""),[Ne,je]=u.useState([]);u.useEffect(()=>{l&&c===1&&ce()},[l,c]);const ce=async()=>{h(!0);try{const G=await j4({name:"",description:"",author:""});N(G.providers),b(G.models),w(G.task_config),M(new Set(G.providers.map($=>$.name))),F(new Set(G.models.map($=>$.name))),C(new Set(Object.keys(G.task_config)))}catch(G){console.error("加载配置失败:",G),aa({title:"加载当前配置失败",variant:"destructive"})}finally{h(!1)}},ge=G=>{const $=new Set(z),A=new Set(S),K=new Set(E);$.has(G)?($.delete(G),j.filter(se=>se.api_provider===G).forEach(se=>A.delete(se.name)),Object.entries(y).forEach(([se,$e])=>{$e.model_list&&($e.model_list.some(J=>A.has(J))||K.delete(se))})):($.add(G),j.filter(se=>se.api_provider===G).forEach(se=>A.add(se.name)),Object.entries(y).forEach(([se,$e])=>{$e.model_list&&$e.model_list.some(J=>{const Z=j.find(Le=>Le.name===J);return Z&&Z.api_provider===G})&&K.add(se)})),M($),F(A),C(K)},pe=G=>{const $=new Set(S),A=new Set(E);$.has(G)?($.delete(G),Object.entries(y).forEach(([K,Re])=>{Re.model_list&&(Re.model_list.some($e=>$.has($e))||A.delete(K))})):($.add(G),Object.entries(y).forEach(([K,Re])=>{Re.model_list&&Re.model_list.includes(G)&&A.add(K)})),F($),C(A)},D=G=>{const $=new Set(E);$.has(G)?$.delete(G):$.add(G),C($)},Q=G=>{Ne.includes(G)?je(Ne.filter($=>$!==G)):Ne.length<5?je([...Ne,G]):aa({title:"最多选择 5 个标签",variant:"destructive"})},B=()=>{z.size===g.length?M(new Set):M(new Set(g.map(G=>G.name)))},ue=()=>{S.size===j.length?F(new Set):F(new Set(j.map(G=>G.name)))},Y=()=>{const G=Object.keys(y);E.size===G.length?C(new Set):C(new Set(G))},we=async()=>{if(!R.trim()){aa({title:"请输入模板名称",variant:"destructive"});return}if(!O.trim()){aa({title:"请输入模板描述",variant:"destructive"});return}if(!L.trim()){aa({title:"请输入作者名称",variant:"destructive"});return}if(z.size===0&&S.size===0&&E.size===0){aa({title:"请至少选择一项配置",variant:"destructive"});return}p(!0);try{const G=g.filter(K=>z.has(K.name)),$=j.filter(K=>S.has(K.name)),A={};for(const[K,Re]of Object.entries(y))E.has(K)&&(A[K]=Re);await h4({name:R.trim(),description:O.trim(),author:L.trim(),tags:Ne,providers:G,models:$,task_config:A}),aa({title:"模板已提交审核,审核通过后将显示在市场中"}),r(!1),fe()}catch(G){console.error("提交失败:",G),aa({title:G instanceof Error?G.message:"提交失败",variant:"destructive"})}finally{p(!1)}},fe=()=>{d(1),H(""),X(""),me(""),je([]),M(new Set),F(new Set),C(new Set)},Ee=2;return e.jsxs(Qs,{open:l,onOpenChange:r,children:[e.jsx(dd,{asChild:!0,children:a||e.jsxs(_,{variant:"outline",children:[e.jsx(mv,{className:"w-4 h-4 mr-2"}),"分享配置"]})}),e.jsxs(Hs,{className:"max-w-2xl max-h-[85vh] flex flex-col",children:[e.jsxs(qs,{children:[e.jsxs(Vs,{className:"flex items-center gap-2",children:[e.jsx(xa,{className:"w-5 h-5"}),"分享配置模板"]}),e.jsxs(at,{children:["步骤 ",c," / ",Ee,":",c===1&&"选择要分享的配置",c===2&&"填写模板信息"]})]}),e.jsx(ts,{className:"h-[calc(85vh-220px)] pr-4",children:m?e.jsxs("div",{className:"py-8 text-center",children:[e.jsx(Fs,{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(ht,{children:[e.jsx(Yt,{className:"h-4 w-4"}),e.jsx(Jn,{children:"安全提示"}),e.jsxs(ft,{children:["分享的配置将",e.jsx("strong",{children:"不包含"})," API Key,其他用户需要自行配置。"]})]}),e.jsxs(Jt,{defaultValue:"providers",className:"w-full",children:[e.jsxs(Gt,{className:"grid w-full grid-cols-3",children:[e.jsxs(Xe,{value:"providers",children:[e.jsx(Hl,{className:"w-4 h-4 mr-2"}),"API 提供商",e.jsxs(Ce,{variant:"secondary",className:"ml-2",children:[z.size,"/",g.length]})]}),e.jsxs(Xe,{value:"models",children:[e.jsx(Wn,{className:"w-4 h-4 mr-2"}),"模型配置",e.jsxs(Ce,{variant:"secondary",className:"ml-2",children:[S.size,"/",j.length]})]}),e.jsxs(Xe,{value:"tasks",children:[e.jsx(er,{className:"w-4 h-4 mr-2"}),"任务配置",e.jsxs(Ce,{variant:"secondary",className:"ml-2",children:[E.size,"/",Object.keys(y).length]})]})]}),e.jsx(Ss,{value:"providers",className:"space-y-2 mt-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(_,{variant:"ghost",size:"sm",onClick:B,children:z.size===g.length?"取消全选":"全选"})}),g.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-2",children:"暂无提供商配置"}):g.map(G=>e.jsxs("div",{className:"flex items-center space-x-2 p-2 rounded hover:bg-muted",children:[e.jsx(tt,{id:`provider-${G.name}`,checked:z.has(G.name),onCheckedChange:()=>ge(G.name)}),e.jsxs(T,{htmlFor:`provider-${G.name}`,className:"flex-1 cursor-pointer",children:[e.jsx("span",{className:"font-medium",children:G.name}),e.jsx("span",{className:"text-xs text-muted-foreground ml-2",children:G.base_url})]}),e.jsx(Ce,{variant:"outline",className:"text-xs",children:G.client_type})]},G.name))]})}),e.jsx(Ss,{value:"models",className:"space-y-2 mt-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(_,{variant:"ghost",size:"sm",onClick:ue,children:S.size===j.length?"取消全选":"全选"})}),j.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-2",children:"暂无模型配置"}):j.map(G=>e.jsxs("div",{className:"flex items-center space-x-2 p-2 rounded hover:bg-muted",children:[e.jsx(tt,{id:`model-${G.name}`,checked:S.has(G.name),onCheckedChange:()=>pe(G.name)}),e.jsxs(T,{htmlFor:`model-${G.name}`,className:"flex-1 cursor-pointer",children:[e.jsx("span",{className:"font-medium",children:G.name}),e.jsx("span",{className:"text-xs text-muted-foreground ml-2",children:G.model_identifier})]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:G.api_provider})]},G.name))]})}),e.jsx(Ss,{value:"tasks",className:"space-y-2 mt-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(_,{variant:"ghost",size:"sm",onClick:Y,children:E.size===Object.keys(y).length?"取消全选":"全选"})}),Object.keys(y).length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-2",children:"暂无任务配置"}):Object.entries(y).map(([G,$])=>e.jsxs("div",{className:"space-y-2 p-2 rounded hover:bg-muted",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(tt,{id:`task-${G}`,checked:E.has(G),onCheckedChange:()=>D(G)}),e.jsx(T,{htmlFor:`task-${G}`,className:"flex-1 cursor-pointer",children:e.jsx("span",{className:"font-medium",children:v4[G]||G})}),e.jsxs(Ce,{variant:"outline",className:"text-xs",children:[$.model_list.length," 个模型"]})]}),$.model_list&&$.model_list.length>0&&e.jsx("div",{className:"ml-6 flex flex-wrap gap-1",children:$.model_list.map(A=>{const K=j.find(se=>se.name===A),Re=S.has(A);return e.jsxs(Ce,{variant:Re?"default":"outline",className:"text-xs cursor-pointer hover:opacity-80 transition-opacity",onClick:()=>pe(A),children:[A,K&&e.jsxs("span",{className:"ml-1 opacity-70",children:["(",K.api_provider,")"]})]},A)})})]},G))]})})]})]}),c===2&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-4 text-sm p-3 bg-muted rounded-lg",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Hl,{className:"w-4 h-4"}),z.size," 个提供商"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Wn,{className:"w-4 h-4"}),S.size," 个模型"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(er,{className:"w-4 h-4"}),E.size," 个任务"]})]}),e.jsx(la,{}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"pack-name",children:"模板名称 *"}),e.jsx(ne,{id:"pack-name",placeholder:"例如:高性价比国产模型配置",value:R,onChange:G=>H(G.target.value),maxLength:50}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[R.length,"/50"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"pack-description",children:"模板描述 *"}),e.jsx(pt,{id:"pack-description",placeholder:"详细描述这个配置模板的特点、适用场景等...",value:O,onChange:G=>X(G.target.value),rows:4,maxLength:500}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[O.length,"/500"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"pack-author",children:"作者名称 *"}),e.jsx(ne,{id:"pack-author",placeholder:"你的昵称或 ID",value:L,onChange:G=>me(G.target.value),maxLength:30})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"标签(可选,最多 5 个)"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:N4.map(G=>e.jsxs(Ce,{variant:Ne.includes(G)?"default":"outline",className:"cursor-pointer transition-colors",onClick:()=>Q(G),children:[Ne.includes(G)&&e.jsx(Ot,{className:"w-3 h-3 mr-1"}),e.jsx(cd,{className:"w-3 h-3 mr-1"}),G]},G))})]})]}),e.jsxs(ht,{children:[e.jsx(Yt,{className:"h-4 w-4"}),e.jsx(Jn,{children:"审核说明"}),e.jsx(ft,{children:"提交后需要经过审核才能在市场中展示。审核通常在 1-3 个工作日内完成。"})]})]})]})}),e.jsxs(gt,{className:"flex justify-between pt-4 border-t",children:[e.jsx("div",{children:c>1&&e.jsx(_,{variant:"outline",onClick:()=>d(c-1),disabled:f,children:"上一步"})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(_,{variant:"outline",onClick:()=>{r(!1),fe()},disabled:f,children:"取消"}),cd(c+1),disabled:m||z.size===0&&S.size===0&&E.size===0,children:"下一步"}):e.jsxs(_,{onClick:we,disabled:f,children:[f&&e.jsx(Fs,{className:"w-4 h-4 mr-2 animate-spin"}),"提交审核"]})]})]})]})]})}function y4({value:a,label:l,onRemove:r}){const{attributes:c,listeners:d,setNodeRef:m,transform:h,transition:f,isDragging:p}=Cv({id:a}),g={transform:Tv.Transform.toString(h),transition:f,opacity:p?.5:1},N=b=>{b.preventDefault(),b.stopPropagation(),r(a)},j=b=>{b.stopPropagation()};return e.jsx("div",{ref:m,style:g,className:P("inline-flex items-center gap-1",p&&"shadow-lg"),children:e.jsxs(Ce,{variant:"secondary",className:"cursor-move hover:bg-secondary/80 flex items-center gap-1",children:[e.jsx("div",{...c,...d,className:"cursor-grab active:cursor-grabbing flex items-center",children:e.jsx(dv,{className:"h-3 w-3 text-muted-foreground"})}),e.jsx("span",{children:l}),e.jsx("span",{role:"button",tabIndex:0,className:"ml-1 rounded-sm hover:bg-destructive/20 focus:outline-none focus:ring-1 focus:ring-destructive cursor-pointer",onClick:N,onPointerDown:j,onMouseDown:b=>b.stopPropagation(),onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),N(b))},children:e.jsx(Sa,{className:"h-3 w-3 hover:text-destructive",strokeWidth:2,fill:"none"})})]})})}function w4({options:a,selected:l,onChange:r,placeholder:c="选择选项...",emptyText:d="未找到选项",className:m}){const[h,f]=u.useState(!1),p=vv(Qo(yv,{activationConstraint:{distance:8}}),Qo(bv,{coordinateGetter:Nv})),g=b=>{l.includes(b)?r(l.filter(y=>y!==b)):r([...l,b])},N=b=>{r(l.filter(y=>y!==b))},j=b=>{const{active:y,over:w}=b;if(w&&y.id!==w.id){const z=l.indexOf(y.id),M=l.indexOf(w.id);r(wv(l,z,M))}};return e.jsxs(cl,{open:h,onOpenChange:f,children:[e.jsx(ol,{asChild:!0,children:e.jsxs(_,{variant:"outline",role:"combobox","aria-expanded":h,className:P("w-full justify-between min-h-10 h-auto",m),children:[e.jsx(_v,{sensors:p,collisionDetection:Sv,onDragEnd:j,children:e.jsx(kv,{items:l,strategy:p_,children:e.jsx("div",{className:"flex gap-1 flex-wrap flex-1",children:l.length===0?e.jsx("span",{className:"text-muted-foreground",children:c}):l.map(b=>{const y=a.find(w=>w.value===b);return e.jsx(y4,{value:b,label:y?.label||b,onRemove:N},b)})})})}),e.jsx(mx,{className:"ml-2 h-4 w-4 shrink-0 opacity-50",strokeWidth:2,fill:"none"})]})}),e.jsx(tl,{className:"w-full p-0",align:"start",children:e.jsxs(md,{children:[e.jsx(xd,{placeholder:"搜索...",className:"h-9"}),e.jsxs(hd,{children:[e.jsx(fd,{children:d}),e.jsx(uc,{children:a.map(b=>{const y=l.includes(b.value);return e.jsxs(mc,{value:b.value,onSelect:()=>g(b.value),children:[e.jsx("div",{className:P("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",y?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(Ot,{className:"h-3 w-3",strokeWidth:2,fill:"none"})}),e.jsx("span",{children:b.label})]},b.value)})})]})]})})]})}const Ul=Bs.memo(function({title:l,description:r,taskConfig:c,modelNames:d,onChange:m,hideTemperature:h=!1,hideMaxTokens:f=!1,dataTour:p}){const g=N=>{m("model_list",N)};return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-base sm:text-lg",children:l}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground mt-1",children:r})]}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-2","data-tour":p,children:[e.jsx(T,{children:"模型列表"}),e.jsx(w4,{options:d.map(N=>({label:N,value:N})),selected:c.model_list||[],onChange:g,placeholder:"选择模型...",emptyText:"暂无可用模型"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[!h&&e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{children:"温度"}),e.jsx(ne,{type:"number",step:"0.1",min:"0",max:"1",value:c.temperature??.3,onChange:N=>{const j=parseFloat(N.target.value);!isNaN(j)&&j>=0&&j<=1&&m("temperature",j)},className:"w-20 h-8 text-sm"})]}),e.jsx(el,{value:[c.temperature??.3],onValueChange:N=>m("temperature",N[0]),min:0,max:1,step:.1,className:"w-full"})]}),!f&&e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"最大 Token"}),e.jsx(ne,{type:"number",step:"1",min:"1",value:c.max_tokens??1024,onChange:N=>m("max_tokens",parseInt(N.target.value))})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{children:"慢请求阈值 (秒)"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"超时警告"})]}),e.jsx(ne,{type:"number",step:"1",min:"1",value:c.slow_threshold??15,onChange:N=>{const j=parseInt(N.target.value);!isNaN(j)&&j>=1&&m("slow_threshold",j)},placeholder:"15"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"模型响应时间超过此阈值将输出警告日志"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"模型选择策略"}),e.jsxs(Pe,{value:c.selection_strategy??"balance",onValueChange:N=>m("selection_strategy",N),children:[e.jsx(Be,{children:e.jsx(Fe,{placeholder:"选择模型选择策略"})}),e.jsxs(Ie,{children:[e.jsx(W,{value:"balance",children:"负载均衡(balance)"}),e.jsx(W,{value:"random",children:"随机选择(random)"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"负载均衡:优先选择使用次数少的模型。随机选择:完全随机从模型列表中选择"})]})]})]})}),_4=Bs.memo(function({paginatedModels:l,allModels:r,onEdit:c,onDelete:d,isModelUsed:m,searchQuery:h}){return l.length===0?e.jsx("div",{className:"md:hidden text-center text-muted-foreground py-8 rounded-lg border bg-card",children:h?"未找到匹配的模型":"暂无模型配置"}):e.jsx("div",{className:"md:hidden space-y-3",children:l.map((f,p)=>{const g=r.findIndex(j=>j===f),N=m(f.name);return e.jsxs("div",{className:"rounded-lg border bg-card p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("h3",{className:"font-semibold text-base",children:f.name}),e.jsx(Ce,{variant:N?"default":"secondary",className:N?"bg-green-600 hover:bg-green-700":"",children:N?"已使用":"未使用"})]}),e.jsx("p",{className:"text-xs text-muted-foreground break-all",title:f.model_identifier,children:f.model_identifier})]}),e.jsxs("div",{className:"flex gap-1 flex-shrink-0",children:[e.jsxs(_,{variant:"default",size:"sm",onClick:()=>c(f,g),children:[e.jsx(Zn,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"编辑"]}),e.jsxs(_,{size:"sm",onClick:()=>d(g),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(os,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"删除"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"提供商"}),e.jsx("p",{className:"font-medium",children:f.api_provider})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"模型温度"}),e.jsx("p",{className:"font-medium",children:f.temperature!=null?f.temperature:e.jsx("span",{className:"text-muted-foreground",children:"默认"})})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"输入价格"}),e.jsxs("p",{className:"font-medium",children:["¥",f.price_in,"/M"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"输出价格"}),e.jsxs("p",{className:"font-medium",children:["¥",f.price_out,"/M"]})]})]})]},p)})})}),S4=Bs.memo(function({paginatedModels:l,allModels:r,filteredModels:c,selectedModels:d,onEdit:m,onDelete:h,onToggleSelection:f,onToggleSelectAll:p,isModelUsed:g,searchQuery:N}){return e.jsx("div",{className:"hidden md:block rounded-lg border bg-card overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(ql,{children:[e.jsx(Vl,{children:e.jsxs(_t,{children:[e.jsx(ns,{className:"w-12",children:e.jsx(tt,{checked:d.size===c.length&&c.length>0,onCheckedChange:p})}),e.jsx(ns,{className:"w-24",children:"使用状态"}),e.jsx(ns,{children:"模型名称"}),e.jsx(ns,{children:"模型标识符"}),e.jsx(ns,{children:"提供商"}),e.jsx(ns,{className:"text-center",children:"温度"}),e.jsx(ns,{className:"text-right",children:"输入价格"}),e.jsx(ns,{className:"text-right",children:"输出价格"}),e.jsx(ns,{className:"text-right",children:"操作"})]})}),e.jsx(Gl,{children:l.length===0?e.jsx(_t,{children:e.jsx(Ze,{colSpan:9,className:"text-center text-muted-foreground py-8",children:N?"未找到匹配的模型":"暂无模型配置"})}):l.map((j,b)=>{const y=r.findIndex(z=>z===j),w=g(j.name);return e.jsxs(_t,{children:[e.jsx(Ze,{children:e.jsx(tt,{checked:d.has(y),onCheckedChange:()=>f(y)})}),e.jsx(Ze,{children:e.jsx(Ce,{variant:w?"default":"secondary",className:w?"bg-green-600 hover:bg-green-700":"",children:w?"已使用":"未使用"})}),e.jsx(Ze,{className:"font-medium",children:j.name}),e.jsx(Ze,{className:"max-w-xs truncate",title:j.model_identifier,children:j.model_identifier}),e.jsx(Ze,{children:j.api_provider}),e.jsx(Ze,{className:"text-center",children:j.temperature!=null?j.temperature:e.jsx("span",{className:"text-muted-foreground",children:"-"})}),e.jsxs(Ze,{className:"text-right",children:["¥",j.price_in,"/M"]}),e.jsxs(Ze,{className:"text-right",children:["¥",j.price_out,"/M"]}),e.jsx(Ze,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(_,{variant:"default",size:"sm",onClick:()=>m(j,y),children:[e.jsx(Zn,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"编辑"]}),e.jsxs(_,{size:"sm",onClick:()=>h(y),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(os,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"删除"]})]})})]},b)})})]})})})}),k4=300*1e3,Zg=new Map,C4=[10,20,50,100],T4=Bs.memo(function({page:l,pageSize:r,totalItems:c,jumpToPage:d,onPageChange:m,onPageSizeChange:h,onJumpToPageChange:f,onJumpToPage:p,onSelectionClear:g}){const N=Math.ceil(c/r),j=y=>{h(parseInt(y)),m(1),g?.()},b=y=>{y.key==="Enter"&&p()};return c===0?null:e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4 mt-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{htmlFor:"page-size-model",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(Pe,{value:r.toString(),onValueChange:j,children:[e.jsx(Be,{id:"page-size-model",className:"w-20",children:e.jsx(Fe,{})}),e.jsx(Ie,{children:C4.map(y=>e.jsx(W,{value:y.toString(),children:y},y))})]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["显示 ",(l-1)*r+1," 到"," ",Math.min(l*r,c)," 条,共 ",c," 条"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>m(1),disabled:l===1,className:"hidden sm:flex",children:e.jsx(kn,{className:"h-4 w-4"})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>m(Math.max(1,l-1)),disabled:l===1,children:[e.jsx(Pa,{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(ne,{type:"number",value:d,onChange:y=>f(y.target.value),onKeyDown:b,placeholder:l.toString(),className:"w-16 h-8 text-center",min:1,max:N}),e.jsx(_,{variant:"outline",size:"sm",onClick:p,disabled:!d,className:"h-8",children:"跳转"})]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>m(l+1),disabled:l>=N,children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(ra,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>m(N),disabled:l>=N,className:"hidden sm:flex",children:e.jsx(Cn,{className:"h-4 w-4"})})]})]})});function E4(a){const{models:l,taskConfig:r,debounceMs:c=2e3,onSavingChange:d,onUnsavedChange:m}=a,h=u.useRef(null),f=u.useRef(null),p=u.useRef(!0),g=u.useCallback(()=>{h.current&&(clearTimeout(h.current),h.current=null),f.current&&(clearTimeout(f.current),f.current=null)},[]),N=u.useCallback(y=>{const w={model_identifier:y.model_identifier,name:y.name,api_provider:y.api_provider,price_in:y.price_in??0,price_out:y.price_out??0,force_stream_mode:y.force_stream_mode??!1,extra_params:y.extra_params??{}};return y.temperature!=null&&(w.temperature=y.temperature),y.max_tokens!=null&&(w.max_tokens=y.max_tokens),w},[]),j=u.useCallback(async y=>{try{d?.(!0);const w=y.map(N);await Wm("models",w),m?.(!1)}catch(w){console.error("自动保存模型列表失败:",w),m?.(!0)}finally{d?.(!1)}},[d,m,N]),b=u.useCallback(async y=>{try{d?.(!0),await Wm("model_task_config",y),m?.(!1)}catch(w){console.error("自动保存任务配置失败:",w),m?.(!0)}finally{d?.(!1)}},[d,m]);return u.useEffect(()=>{if(!p.current)return m?.(!0),h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{j(l)},c),()=>{h.current&&clearTimeout(h.current)}},[l,j,c,m]),u.useEffect(()=>{if(!(p.current||!r))return m?.(!0),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>{b(r)},c),()=>{f.current&&clearTimeout(f.current)}},[r,b,c,m]),u.useEffect(()=>()=>{g()},[g]),{clearTimers:g,initialLoadRef:p}}function M4(a={}){const{onCloseEditDialog:l}=a,r=ha(),{registerTour:c,startTour:d,state:m,goToStep:h}=Ex(),f=u.useRef(m.stepIndex);return u.useEffect(()=>{c(gl,aN)},[c]),u.useEffect(()=>{if(m.activeTourId===gl&&m.isRunning){const g=lN[m.stepIndex];g&&!window.location.pathname.endsWith(g.replace("/config/",""))&&r({to:g})}},[m.stepIndex,m.activeTourId,m.isRunning,r]),u.useEffect(()=>{if(m.activeTourId===gl&&m.isRunning){const g=f.current,N=m.stepIndex;g>=12&&g<=17&&N<12&&l?.(),f.current=N}},[m.stepIndex,m.activeTourId,m.isRunning,l]),u.useEffect(()=>{if(m.activeTourId!==gl||!m.isRunning)return;const g=N=>{const j=N.target,b=m.stepIndex;b===2&&j.closest('[data-tour="add-provider-button"]')?setTimeout(()=>h(3),300):b===9&&j.closest('[data-tour="provider-cancel-button"]')?setTimeout(()=>h(10),300):b===11&&j.closest('[data-tour="add-model-button"]')?setTimeout(()=>h(12),300):b===17&&j.closest('[data-tour="model-cancel-button"]')?setTimeout(()=>h(18),300):b===18&&j.closest('[data-tour="tasks-tab-trigger"]')&&setTimeout(()=>h(19),300)};return document.addEventListener("click",g,!0),()=>document.removeEventListener("click",g,!0)},[m,h]),{startTour:u.useCallback(()=>{d(gl)},[d]),isRunning:m.isRunning&&m.activeTourId===gl,stepIndex:m.stepIndex}}function A4(a){const{getProviderConfig:l}=a,[r,c]=u.useState([]),[d,m]=u.useState(!1),[h,f]=u.useState(null),[p,g]=u.useState(null),N=u.useCallback(()=>{c([]),f(null),g(null)},[]),j=u.useCallback(async(b,y=!1)=>{const w=l(b);if(!w?.base_url){c([]),g(null),f('提供商配置不完整,请先在"模型提供商配置"中配置');return}if(!w.api_key){c([]),g(null),f('该提供商未配置 API Key,请先在"模型提供商配置"中填写');return}const z=n4(w.base_url);if(g(z),!z?.modelFetcher){c([]),f(null);return}const M=`${b}:${w.base_url}`,S=Zg.get(M);if(!y&&S&&Date.now()-S.timestampE(!1)}),{clearTimers:V,initialLoadRef:Ke}=E4({models:a,taskConfig:p,onSavingChange:z,onUnsavedChange:S}),He=u.useCallback((ae,oe)=>{if(!ae)return;const qe=new Set(oe.map(Ca=>Ca.name)),Ys=[],Ps=[],vt=[{key:"utils",label:"工具模型"},{key:"tool_use",label:"工具调用模型"},{key:"replyer",label:"回复模型"},{key:"planner",label:"规划器模型"},{key:"vlm",label:"视觉模型"},{key:"voice",label:"语音模型"},{key:"embedding",label:"嵌入模型"},{key:"lpmm_entity_extract",label:"LPMM实体抽取"},{key:"lpmm_rdf_build",label:"LPMM关系构建"},{key:"tts_instruct",label:"TTS指令生成"}];for(const{key:Ca,label:ll}of vt){const ml=ae[Ca];if(!ml)continue;if(!ml.model_list||ml.model_list.length===0){Ps.push(ll);continue}const rr=ml.model_list.filter(Ql=>!qe.has(Ql));rr.length>0&&Ys.push({taskName:ll,invalidModels:rr})}le(Ys),xe(Ps)},[]),Je=u.useCallback(async()=>{try{j(!0);const ae=await Nn(),oe=ae.models||[];l(oe),f(oe.map(vt=>vt.name));const qe=ae.api_providers||[];c(qe.map(vt=>vt.name)),m(qe);const Ys=ae.model_task_config||null;g(Ys),He(Ys,oe);const Ps=Ys?.embedding?.model_list||[];J.current=[...Ps],S(!1),Ke.current=!1}catch(ae){console.error("加载配置失败:",ae)}finally{j(!1)}},[Ke,He]);u.useEffect(()=>{Je()},[Je]);const Es=u.useCallback(ae=>d.find(oe=>oe.name===ae),[d]),{availableModels:ms,fetchingModels:Ms,modelFetchError:We,matchedTemplate:Cs,fetchModelsForProvider:rs,clearModels:is}=A4({getProviderConfig:Es});u.useEffect(()=>{F&&C?.api_provider&&rs(C.api_provider)},[F,C?.api_provider,rs]);const ys=async()=>{await Ct()},rt=u.useCallback(()=>{if(!p)return;const ae=new Set(a.map(Ys=>Ys.name)),oe={...p},qe=Object.keys(oe);for(const Ys of qe){const Ps=oe[Ys];Ps&&Ps.model_list&&(Ps.model_list=Ps.model_list.filter(vt=>ae.has(vt)))}g(oe),le([]),Ts({title:"清理完成",description:"已删除所有无效的模型引用"})},[p,a,Ts]),jt=ae=>{const oe={model_identifier:ae.model_identifier,name:ae.name,api_provider:ae.api_provider,price_in:ae.price_in??0,price_out:ae.price_out??0,force_stream_mode:ae.force_stream_mode??!1,extra_params:ae.extra_params??{}};return ae.temperature!=null&&(oe.temperature=ae.temperature),ae.max_tokens!=null&&(oe.max_tokens=ae.max_tokens),oe},Ae=async()=>{try{y(!0),V();const ae=await Nn();ae.models=a.map(jt),ae.model_task_config=p,await lc(ae),S(!1),Ts({title:"保存成功",description:"正在重启麦麦..."}),await ys()}catch(ae){console.error("保存配置失败:",ae),Ts({title:"保存失败",description:ae.message,variant:"destructive"}),y(!1)}},Qe=async()=>{try{y(!0),V();const ae=await Nn();ae.models=a.map(jt),ae.model_task_config=p,await lc(ae),S(!1),Ts({title:"保存成功",description:"模型配置已保存"}),await Je()}catch(ae){console.error("保存配置失败:",ae),Ts({title:"保存失败",description:ae.message,variant:"destructive"})}finally{y(!1)}},As=(ae,oe)=>{ds({}),R(ae||{model_identifier:"",name:"",api_provider:r[0]||"",price_in:0,price_out:0,temperature:null,max_tokens:null,force_stream_mode:!1,extra_params:{}}),O(oe),E(!0)},mt=()=>{if(!C)return;const ae={};if(C.name?.trim()?a.some((vt,Ca)=>H!==null&&Ca===H?!1:vt.name.trim().toLowerCase()===C.name.trim().toLowerCase())&&(ae.name="模型名称已存在,请使用其他名称"):ae.name="请输入模型名称",C.api_provider?.trim()||(ae.api_provider="请选择 API 提供商"),C.model_identifier?.trim()||(ae.model_identifier="请输入模型标识符"),Object.keys(ae).length>0){ds(ae);return}ds({});const oe={model_identifier:C.model_identifier,name:C.name,api_provider:C.api_provider,price_in:C.price_in??0,price_out:C.price_out??0,force_stream_mode:C.force_stream_mode??!1,extra_params:C.extra_params??{}};C.temperature!=null&&(oe.temperature=C.temperature),C.max_tokens!=null&&(oe.max_tokens=C.max_tokens);let qe,Ys=null;if(H!==null?(Ys=a[H].name,qe=[...a],qe[H]=oe):qe=[...a,oe],l(qe),f(qe.map(Ps=>Ps.name)),Ys&&Ys!==oe.name&&p){const Ps=vt=>vt.map(Ca=>Ca===Ys?oe.name:Ca);g({...p,utils:{...p.utils,model_list:Ps(p.utils?.model_list||[])},tool_use:{...p.tool_use,model_list:Ps(p.tool_use?.model_list||[])},replyer:{...p.replyer,model_list:Ps(p.replyer?.model_list||[])},planner:{...p.planner,model_list:Ps(p.planner?.model_list||[])},vlm:{...p.vlm,model_list:Ps(p.vlm?.model_list||[])},voice:{...p.voice,model_list:Ps(p.voice?.model_list||[])},embedding:{...p.embedding,model_list:Ps(p.embedding?.model_list||[])},lpmm_entity_extract:{...p.lpmm_entity_extract,model_list:Ps(p.lpmm_entity_extract?.model_list||[])},lpmm_rdf_build:{...p.lpmm_rdf_build,model_list:Ps(p.lpmm_rdf_build?.model_list||[])},tts_instruct:{...p.tts_instruct,model_list:Ps(p.tts_instruct?.model_list||[])}})}E(!1),R(null),O(null),Ts({title:H!==null?"模型已更新":"模型已添加",description:'配置将在 2 秒后自动保存,或点击右上角"保存配置"按钮立即保存'})},Ht=ae=>{if(!ae&&C){const oe={...C,price_in:C.price_in??0,price_out:C.price_out??0};R(oe)}E(ae)},ca=ae=>{ce(ae),Ne(!0)},Fa=()=>{if(je!==null){const ae=a.filter((oe,qe)=>qe!==je);l(ae),f(ae.map(oe=>oe.name)),He(p,ae),Ts({title:"删除成功",description:'配置将在 2 秒后自动保存,或点击右上角"保存配置"按钮立即保存'})}Ne(!1),ce(null)},Xt=ae=>{const oe=new Set(D);oe.has(ae)?oe.delete(ae):oe.add(ae),Q(oe)},te=()=>{if(D.size===es.length)Q(new Set);else{const ae=es.map((oe,qe)=>a.findIndex(Ys=>Ys===es[qe]));Q(new Set(ae))}},_e=()=>{if(D.size===0){Ts({title:"提示",description:"请先选择要删除的模型",variant:"default"});return}ue(!0)},U=()=>{const ae=D.size,oe=a.filter((qe,Ys)=>!D.has(Ys));l(oe),f(oe.map(qe=>qe.name)),He(p,oe),Q(new Set),ue(!1),Ts({title:"批量删除成功",description:`已删除 ${ae} 个模型,配置将在 2 秒后自动保存`})},Se=(ae,oe,qe)=>{if(!p)return;if(ae==="embedding"&&oe==="model_list"&&Array.isArray(qe)){const Ps=J.current,vt=qe;if((Ps.length!==vt.length||Ps.some(ll=>!vt.includes(ll))||vt.some(ll=>!Ps.includes(ll)))&&Ps.length>0){Z.current={field:oe,value:qe},cs(!0);return}}const Ys={...p,[ae]:{...p[ae],[oe]:qe}};g(Ys),He(Ys,a),ae==="embedding"&&oe==="model_list"&&Array.isArray(qe)&&(J.current=[...qe])},as=()=>{if(!p||!Z.current)return;const{field:ae,value:oe}=Z.current,qe={...p,embedding:{...p.embedding,[ae]:oe}};g(qe),He(qe,a),ae==="model_list"&&Array.isArray(oe)&&(J.current=[...oe]),Z.current=null,cs(!1),Ts({title:"嵌入模型已更新",description:"建议重新生成知识库向量以确保最佳匹配精度"})},us=()=>{Z.current=null,cs(!1)},es=a.filter(ae=>{if(!ge)return!0;const oe=ge.toLowerCase();return ae.name.toLowerCase().includes(oe)||ae.model_identifier.toLowerCase().includes(oe)||ae.api_provider.toLowerCase().includes(oe)}),Tt=Math.ceil(es.length/fe),$s=es.slice((Y-1)*fe,Y*fe),pa=()=>{const ae=parseInt(G);ae>=1&&ae<=Tt&&(we(ae),$(""))},oa=ae=>p?[p.utils?.model_list||[],p.tool_use?.model_list||[],p.replyer?.model_list||[],p.planner?.model_list||[],p.vlm?.model_list||[],p.voice?.model_list||[],p.embedding?.model_list||[],p.lpmm_entity_extract?.model_list||[],p.lpmm_rdf_build?.model_list||[],p.tts_instruct?.model_list||[]].some(qe=>qe.includes(ae)):!1;return N?e.jsx(ts,{className:"h-full",children:e.jsx("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("p",{className:"text-muted-foreground",children:"加载中..."})})})}):e.jsx(ts,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"模型管理与分配"}),e.jsx("p",{className:"text-muted-foreground mt-1 sm:mt-2 text-sm sm:text-base",children:"添加模型并为模型分配功能"})]}),e.jsxs("div",{className:"flex gap-2 w-full sm:w-auto",children:[e.jsx(b4,{trigger:e.jsxs(_,{variant:"outline",size:"sm",className:"flex-1 sm:flex-none",children:[e.jsx(mv,{className:"mr-2 h-4 w-4"}),"分享配置"]})}),e.jsxs(_,{onClick:Qe,disabled:b||w||!M||ia,size:"sm",variant:"outline",className:"flex-1 sm:flex-none sm:min-w-[120px]",children:[e.jsx(gc,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),b?"保存中...":w?"自动保存中...":M?"保存配置":"已保存"]}),e.jsxs(bs,{children:[e.jsx(wt,{asChild:!0,children:e.jsxs(_,{disabled:b||w||ia,size:"sm",className:"flex-1 sm:flex-none sm:min-w-[120px]",children:[e.jsx(pc,{className:"mr-2 h-4 w-4"}),ia?"重启中...":M?"保存并重启":"重启麦麦"]})}),e.jsxs(xs,{children:[e.jsxs(hs,{children:[e.jsx(ps,{children:"确认重启麦麦?"}),e.jsx(gs,{asChild:!0,children:e.jsx("div",{children:e.jsx("p",{children:M?"当前有未保存的配置更改。点击确认将先保存配置,然后重启麦麦使新配置生效。重启过程中麦麦将暂时离线。":"即将重启麦麦主程序。重启过程中麦麦将暂时离线,配置将在重启后生效。"})})})]}),e.jsxs(fs,{children:[e.jsx(vs,{children:"取消"}),e.jsx(js,{onClick:M?Ae:ys,children:M?"保存并重启":"确认重启"})]})]})]})]})]}),e.jsxs(ht,{children:[e.jsx(Yt,{className:"h-4 w-4"}),e.jsxs(ft,{children:["配置更新后需要",e.jsx("strong",{children:"重启麦麦"}),'才能生效。你可以点击右上角的"保存并重启"按钮一键完成保存和重启。']})]}),Le.length>0&&e.jsxs(ht,{variant:"destructive",children:[e.jsx(Lt,{className:"h-4 w-4"}),e.jsxs(ft,{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("strong",{children:"检测到无效的模型引用"}),e.jsx("div",{className:"mt-2 space-y-1",children:Le.map(({taskName:ae,invalidModels:oe})=>e.jsxs("div",{className:"text-sm",children:[e.jsx("strong",{children:ae})," 引用了不存在的模型: ",oe.join(", ")]},ae))})]}),e.jsx(_,{variant:"outline",size:"sm",className:"shrink-0 bg-background hover:bg-accent",onClick:rt,children:"一键清理"})]})]}),De.length>0&&e.jsxs(ht,{variant:"default",className:"border-yellow-500/50 bg-yellow-500/10",children:[e.jsx(Lt,{className:"h-4 w-4 text-yellow-600"}),e.jsxs(ft,{children:[e.jsx("strong",{className:"text-yellow-600",children:"以下任务未配置模型"}),e.jsxs("div",{className:"mt-2 text-sm",children:[De.join("、")," 还未分配模型,这些功能将无法正常工作。"]})]})]}),e.jsxs(ht,{className:"hidden lg:flex border-primary/30 bg-primary/5 cursor-pointer hover:bg-primary/10 transition-colors",onClick:ut,children:[e.jsx(U1,{className:"h-4 w-4 text-primary"}),e.jsxs(ft,{className:"flex items-center justify-between",children:[e.jsxs("span",{children:[e.jsx("strong",{className:"text-primary",children:"新手引导:"}),"不知道如何配置模型?点击这里开始学习如何为麦麦的组件分配模型。"]}),e.jsx(_,{variant:"outline",size:"sm",className:"ml-4 shrink-0",children:"开始引导"})]})]}),e.jsxs(Jt,{defaultValue:"models",className:"w-full",children:[e.jsxs(Gt,{className:"grid w-full max-w-full sm:max-w-md grid-cols-2",children:[e.jsx(Xe,{value:"models",children:"添加模型"}),e.jsx(Xe,{value:"tasks","data-tour":"tasks-tab-trigger",children:"为模型分配功能"})]}),e.jsxs(Ss,{value:"models",className:"space-y-4 mt-0",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center gap-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"配置可用的模型列表"}),e.jsxs("div",{className:"flex gap-2 w-full sm:w-auto",children:[D.size>0&&e.jsxs(_,{onClick:_e,size:"sm",variant:"destructive",className:"w-full sm:w-auto",children:[e.jsx(os,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),"批量删除 (",D.size,")"]}),e.jsxs(_,{onClick:()=>As(null,null),size:"sm",variant:"outline",className:"w-full sm:w-auto","data-tour":"add-model-button",children:[e.jsx(Xs,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),"添加模型"]})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center gap-2",children:[e.jsxs("div",{className:"relative w-full sm:flex-1 sm:max-w-sm",children:[e.jsx($t,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ne,{placeholder:"搜索模型名称、标识符或提供商...",value:ge,onChange:ae=>pe(ae.target.value),className:"pl-9"})]}),ge&&e.jsxs("p",{className:"text-sm text-muted-foreground whitespace-nowrap",children:["找到 ",es.length," 个结果"]})]}),e.jsx(_4,{paginatedModels:$s,allModels:a,onEdit:As,onDelete:ca,isModelUsed:oa,searchQuery:ge}),e.jsx(S4,{paginatedModels:$s,allModels:a,filteredModels:es,selectedModels:D,onEdit:As,onDelete:ca,onToggleSelection:Xt,onToggleSelectAll:te,isModelUsed:oa,searchQuery:ge}),e.jsx(T4,{page:Y,pageSize:fe,totalItems:es.length,jumpToPage:G,onPageChange:we,onPageSizeChange:Ee,onJumpToPageChange:$,onJumpToPage:pa,onSelectionClear:()=>Q(new Set)})]}),e.jsxs(Ss,{value:"tasks",className:"space-y-6 mt-0",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"为不同的任务配置使用的模型和参数"}),p&&e.jsxs("div",{className:"grid gap-4 sm:gap-6",children:[e.jsx(Ul,{title:"组件模型 (utils)",description:"用于表情包、取名、关系、情绪变化等组件",taskConfig:p.utils,modelNames:h,onChange:(ae,oe)=>Se("utils",ae,oe),dataTour:"task-model-select"}),e.jsx(Ul,{title:"工具调用模型 (tool_use)",description:"需要使用支持工具调用的模型",taskConfig:p.tool_use,modelNames:h,onChange:(ae,oe)=>Se("tool_use",ae,oe)}),e.jsx(Ul,{title:"首要回复模型 (replyer)",description:"用于表达器和表达方式学习",taskConfig:p.replyer,modelNames:h,onChange:(ae,oe)=>Se("replyer",ae,oe)}),e.jsx(Ul,{title:"TTS 指令模型 (tts_instruct)",description:"用于生成语速/情绪/停顿的 TTS instruct",taskConfig:p.tts_instruct||{model_list:[],temperature:.2,max_tokens:128,slow_threshold:10,selection_strategy:"random"},modelNames:h,onChange:(ae,oe)=>Se("tts_instruct",ae,oe)}),e.jsx(Ul,{title:"决策模型 (planner)",description:"负责决定麦麦该什么时候回复",taskConfig:p.planner,modelNames:h,onChange:(ae,oe)=>Se("planner",ae,oe)}),e.jsx(Ul,{title:"图像识别模型 (vlm)",description:"视觉语言模型",taskConfig:p.vlm,modelNames:h,onChange:(ae,oe)=>Se("vlm",ae,oe),hideTemperature:!0}),e.jsx(Ul,{title:"语音识别模型 (voice)",description:"语音转文字",taskConfig:p.voice,modelNames:h,onChange:(ae,oe)=>Se("voice",ae,oe),hideTemperature:!0,hideMaxTokens:!0}),e.jsx(Ul,{title:"嵌入模型 (embedding)",description:"用于向量化",taskConfig:p.embedding,modelNames:h,onChange:(ae,oe)=>Se("embedding",ae,oe),hideTemperature:!0,hideMaxTokens:!0}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"LPMM 知识库模型"}),e.jsx(Ul,{title:"实体提取模型 (lpmm_entity_extract)",description:"从文本中提取实体",taskConfig:p.lpmm_entity_extract,modelNames:h,onChange:(ae,oe)=>Se("lpmm_entity_extract",ae,oe)}),e.jsx(Ul,{title:"RDF 构建模型 (lpmm_rdf_build)",description:"构建知识图谱",taskConfig:p.lpmm_rdf_build,modelNames:h,onChange:(ae,oe)=>Se("lpmm_rdf_build",ae,oe)})]})]})]})]}),e.jsx(Qs,{open:F,onOpenChange:Ht,children:e.jsxs(Hs,{className:"max-w-[95vw] sm:max-w-2xl max-h-[90vh] overflow-y-auto","data-tour":"model-dialog",preventOutsideClose:Is,children:[e.jsxs(qs,{children:[e.jsx(Vs,{children:H!==null?"编辑模型":"添加模型"}),e.jsx(at,{children:"配置模型的基本信息和参数"})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid gap-2","data-tour":"model-name-input",children:[e.jsx(T,{htmlFor:"model_name",className:Me.name?"text-destructive":"",children:"模型名称 *"}),e.jsx(ne,{id:"model_name",value:C?.name||"",onChange:ae=>{R(oe=>oe?{...oe,name:ae.target.value}:null),Me.name&&ds(oe=>({...oe,name:void 0}))},placeholder:"例如: qwen3-30b",className:Me.name?"border-destructive focus-visible:ring-destructive":""}),Me.name?e.jsx("p",{className:"text-xs text-destructive",children:Me.name}):e.jsx("p",{className:"text-xs text-muted-foreground",children:"用于在任务配置中引用此模型"})]}),e.jsxs("div",{className:"grid gap-2","data-tour":"model-provider-select",children:[e.jsx(T,{htmlFor:"api_provider",className:Me.api_provider?"text-destructive":"",children:"API 提供商 *"}),e.jsxs(Pe,{value:C?.api_provider||"",onValueChange:ae=>{R(oe=>oe?{...oe,api_provider:ae}:null),is(),Me.api_provider&&ds(oe=>({...oe,api_provider:void 0}))},children:[e.jsx(Be,{id:"api_provider",className:Me.api_provider?"border-destructive focus-visible:ring-destructive":"",children:e.jsx(Fe,{placeholder:"选择提供商"})}),e.jsx(Ie,{children:r.map(ae=>e.jsx(W,{value:ae,children:ae},ae))})]}),Me.api_provider&&e.jsx("p",{className:"text-xs text-destructive",children:Me.api_provider})]}),e.jsxs("div",{className:"grid gap-2","data-tour":"model-identifier-input",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{htmlFor:"model_identifier",className:Me.model_identifier?"text-destructive":"",children:"模型标识符 *"}),Cs?.modelFetcher&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ce,{variant:"secondary",className:"text-xs",children:Cs.display_name}),e.jsx(_,{variant:"ghost",size:"sm",className:"h-6 px-2",onClick:()=>C?.api_provider&&rs(C.api_provider,!0),disabled:Ms,children:Ms?e.jsx(Fs,{className:"h-3 w-3 animate-spin"}):e.jsx(dt,{className:"h-3 w-3"})})]})]}),Cs?.modelFetcher?e.jsxs(cl,{open:Re,onOpenChange:se,children:[e.jsx(ol,{asChild:!0,children:e.jsxs(_,{variant:"outline",role:"combobox","aria-expanded":Re,className:"w-full justify-between font-normal",disabled:Ms||!!We,children:[Ms?e.jsxs("span",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(Fs,{className:"h-4 w-4 animate-spin"}),"正在获取模型列表..."]}):We?e.jsx("span",{className:"text-muted-foreground text-sm",children:"点击下方输入框手动填写"}):C?.model_identifier?e.jsx("span",{className:"truncate",children:C.model_identifier}):e.jsx("span",{className:"text-muted-foreground",children:"搜索或选择模型..."}),e.jsx(mx,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(tl,{className:"p-0",align:"start",style:{width:"var(--radix-popover-trigger-width)"},children:e.jsxs(md,{children:[e.jsx(xd,{placeholder:"搜索模型..."}),e.jsx(ts,{className:"h-[300px]",children:e.jsxs(hd,{className:"max-h-none overflow-visible",children:[e.jsx(fd,{children:We?e.jsxs("div",{className:"py-4 px-2 text-center space-y-2",children:[e.jsx("p",{className:"text-sm text-destructive",children:We}),!We.includes("API Key")&&e.jsx(_,{variant:"link",size:"sm",onClick:()=>C?.api_provider&&rs(C.api_provider,!0),children:"重试"})]}):"未找到匹配的模型"}),e.jsx(uc,{heading:"可用模型",children:ms.map(ae=>e.jsxs(mc,{value:ae.id,onSelect:()=>{R(oe=>oe?{...oe,model_identifier:ae.id}:null),se(!1)},children:[e.jsx(Ot,{className:`mr-2 h-4 w-4 ${C?.model_identifier===ae.id?"opacity-100":"opacity-0"}`}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:ae.id}),ae.name!==ae.id&&e.jsx("span",{className:"text-xs text-muted-foreground",children:ae.name})]})]},ae.id))}),e.jsx(uc,{heading:"手动输入",children:e.jsxs(mc,{value:"__manual_input__",onSelect:()=>{se(!1)},children:[e.jsx(Zn,{className:"mr-2 h-4 w-4"}),"手动输入模型标识符..."]})})]})})]})})]}):e.jsx(ne,{id:"model_identifier",value:C?.model_identifier||"",onChange:ae=>{R(oe=>oe?{...oe,model_identifier:ae.target.value}:null),Me.model_identifier&&ds(oe=>({...oe,model_identifier:void 0}))},placeholder:"Qwen/Qwen3-30B-A3B-Instruct-2507",className:Me.model_identifier?"border-destructive focus-visible:ring-destructive":""}),Me.model_identifier&&e.jsx("p",{className:"text-xs text-destructive",children:Me.model_identifier}),We&&Cs?.modelFetcher&&!Me.model_identifier&&e.jsxs(ht,{variant:"destructive",className:"mt-2 py-2",children:[e.jsx(Yt,{className:"h-4 w-4"}),e.jsx(ft,{className:"text-xs",children:We})]}),Cs?.modelFetcher&&e.jsx(ne,{value:C?.model_identifier||"",onChange:ae=>{R(oe=>oe?{...oe,model_identifier:ae.target.value}:null),Me.model_identifier&&ds(oe=>({...oe,model_identifier:void 0}))},placeholder:"或手动输入模型标识符",className:`mt-2 ${Me.model_identifier?"border-destructive focus-visible:ring-destructive":""}`}),!Me.model_identifier&&e.jsx("p",{className:"text-xs text-muted-foreground",children:We?'请手动输入模型标识符,或前往"模型提供商配置"检查 API Key':Cs?.modelFetcher?`已识别为 ${Cs.display_name},支持自动获取模型列表`:"API 提供商提供的模型 ID"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"price_in",children:"输入价格 (¥/M token)"}),e.jsx(ne,{id:"price_in",type:"number",step:"0.1",min:"0",value:C?.price_in??"",onChange:ae=>{const oe=ae.target.value===""?null:parseFloat(ae.target.value);R(qe=>qe?{...qe,price_in:oe}:null)},placeholder:"默认: 0"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"price_out",children:"输出价格 (¥/M token)"}),e.jsx(ne,{id:"price_out",type:"number",step:"0.1",min:"0",value:C?.price_out??"",onChange:ae=>{const oe=ae.target.value===""?null:parseFloat(ae.target.value);R(qe=>qe?{...qe,price_out:oe}:null)},placeholder:"默认: 0"})]})]}),e.jsxs("div",{className:"rounded-lg border p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(T,{htmlFor:"enable_model_temperature",className:"cursor-pointer",children:"自定义模型温度"}),e.jsx(Bl,{content:e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-medium",children:"什么是温度(Temperature)?"}),e.jsx("p",{children:"温度控制模型输出的随机性和创造性:"}),e.jsxs("ul",{className:"list-disc list-inside space-y-1 text-xs",children:[e.jsxs("li",{children:[e.jsx("strong",{children:"低温度(0.1-0.3)"}),":更确定、更保守的输出,适合事实性任务"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"中温度(0.5-0.7)"}),":平衡创造性与可控性"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"高温度(0.8-1.0)"}),":更有创意、更多样化的输出"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"极高温度(1.0-2.0)"}),":极度随机,可能产生不可预测的结果"]})]})]}),side:"right",maxWidth:"400px"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"启用后将覆盖「为模型分配功能」中的任务温度配置"})]}),e.jsx(Ge,{id:"enable_model_temperature",checked:C?.temperature!=null,onCheckedChange:ae=>{R(ae?oe=>oe?{...oe,temperature:.5}:null:oe=>oe?{...oe,temperature:null}:null)}})]}),C?.temperature!=null&&e.jsxs("div",{className:"space-y-3 pt-2 border-t",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(T,{className:"text-sm",children:"温度值"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ne,{type:"number",value:C.temperature,onChange:ae=>{const oe=parseFloat(ae.target.value);!isNaN(oe)&&oe>=0&&oe<=2&&R(qe=>qe?{...qe,temperature:oe}:null)},onBlur:ae=>{const oe=parseFloat(ae.target.value);isNaN(oe)||oe<0?R(qe=>qe?{...qe,temperature:0}:null):oe>2&&R(qe=>qe?{...qe,temperature:2}:null)},step:.01,min:0,max:2,className:"w-20 h-8 text-sm text-right tabular-nums"}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>K(!A),className:"h-8 px-2",title:A?"切换到基础模式 (0-1)":"解锁高级范围 (0-2)",children:A?e.jsx($1,{className:"h-4 w-4"}):e.jsx(Jm,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:"0"}),e.jsx(el,{value:[C.temperature],onValueChange:ae=>R(oe=>oe?{...oe,temperature:ae[0]}:null),min:0,max:A?2:1,step:A?.05:.1,className:"flex-1"}),e.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:A?"2":"1"})]}),A&&e.jsxs(ht,{className:"bg-amber-500/10 border-amber-500/20 [&>svg+div]:translate-y-0",children:[e.jsx(Lt,{className:"h-4 w-4 text-amber-500"}),e.jsx(ft,{className:"text-xs text-amber-600 dark:text-amber-400",children:"高级模式:温度 > 1 会产生更随机、更不可预测的输出,请谨慎使用"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:A?"较低(0.1-0.5)产生确定输出,中等(0.5-1.0)平衡创造性,较高(1.0-2.0)产生极度随机输出":"较低的温度(0.1-0.3)产生更确定的输出,较高的温度(0.7-1.0)产生更多样化的输出"})]})]}),e.jsxs("div",{className:"rounded-lg border p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(T,{htmlFor:"enable_model_max_tokens",className:"cursor-pointer",children:"自定义最大 Token"}),e.jsx(Bl,{content:e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-medium",children:"什么是最大 Token?"}),e.jsx("p",{children:"控制模型单次回复的最大长度。1 token ≈ 0.75 个英文单词或 0.5 个中文字符。"}),e.jsxs("ul",{className:"list-disc list-inside space-y-1 text-xs",children:[e.jsxs("li",{children:[e.jsx("strong",{children:"较小值(512-1024)"}),":简短回复,节省成本"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"中等值(2048-4096)"}),":正常对话长度"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"较大值(8192+)"}),":长文本生成,成本较高"]})]})]}),side:"right",maxWidth:"400px"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"启用后将覆盖「为模型分配功能」中的任务最大 Token 配置"})]}),e.jsx(Ge,{id:"enable_model_max_tokens",checked:C?.max_tokens!=null,onCheckedChange:ae=>{R(ae?oe=>oe?{...oe,max_tokens:2048}:null:oe=>oe?{...oe,max_tokens:null}:null)}})]}),C?.max_tokens!=null&&e.jsxs("div",{className:"space-y-2 pt-2 border-t",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{className:"text-sm",children:"最大 Token 数"}),e.jsx(ne,{type:"number",min:"1",max:"128000",value:C.max_tokens,onChange:ae=>{const oe=parseInt(ae.target.value);!isNaN(oe)&&oe>=1&&R(qe=>qe?{...qe,max_tokens:oe}:null)},className:"w-28 h-8 text-sm"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"限制模型单次输出的最大 token 数量,不同模型支持的上限不同"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ge,{id:"force_stream_mode",checked:C?.force_stream_mode||!1,onCheckedChange:ae=>R(oe=>oe?{...oe,force_stream_mode:ae}:null)}),e.jsx(T,{htmlFor:"force_stream_mode",className:"cursor-pointer",children:"强制流式输出模式"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{className:"text-sm font-medium",children:"额外参数"}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(_,{type:"button",variant:"outline",size:"sm",className:"flex-1 justify-start h-9",onClick:()=>L(!0),children:[e.jsx(Sn,{className:"h-4 w-4 mr-2"}),Object.keys(C?.extra_params||{}).length>0?e.jsxs("span",{children:["已配置 ",Object.keys(C?.extra_params||{}).length," 个参数"]}):e.jsx("span",{className:"text-muted-foreground",children:"未配置额外参数"})]})}),Object.keys(C?.extra_params||{}).length>0&&e.jsxs("div",{className:"text-xs text-muted-foreground px-1",children:[Object.keys(C?.extra_params||{}).slice(0,3).map(ae=>e.jsx("span",{className:"inline-block mr-2",children:e.jsx("code",{className:"px-1.5 py-0.5 bg-muted rounded",children:ae})},ae)),Object.keys(C?.extra_params||{}).length>3&&e.jsx("span",{children:"..."})]})]})]}),e.jsxs(gt,{children:[e.jsx(_,{variant:"outline",onClick:()=>E(!1),"data-tour":"model-cancel-button",children:"取消"}),e.jsx(_,{onClick:mt,"data-tour":"model-save-button",children:"保存"})]})]})}),e.jsx(bs,{open:me,onOpenChange:Ne,children:e.jsxs(xs,{children:[e.jsxs(hs,{children:[e.jsx(ps,{children:"确认删除"}),e.jsxs(gs,{children:['确定要删除模型 "',je!==null?a[je]?.name:"",'" 吗? 此操作无法撤销。']})]}),e.jsxs(fs,{children:[e.jsx(vs,{children:"取消"}),e.jsx(js,{onClick:Fa,children:"删除"})]})]})}),e.jsx(bs,{open:B,onOpenChange:ue,children:e.jsxs(xs,{children:[e.jsxs(hs,{children:[e.jsx(ps,{children:"确认批量删除"}),e.jsxs(gs,{children:["确定要删除选中的 ",D.size," 个模型吗? 此操作无法撤销。"]})]}),e.jsxs(fs,{children:[e.jsx(vs,{children:"取消"}),e.jsx(js,{onClick:U,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"批量删除"})]})]})}),e.jsx(bs,{open:$e,onOpenChange:cs,children:e.jsxs(xs,{children:[e.jsxs(hs,{children:[e.jsxs(ps,{className:"flex items-center gap-2",children:[e.jsx(Lt,{className:"h-5 w-5 text-amber-500"}),"更换嵌入模型警告"]}),e.jsx(gs,{asChild:!0,children:e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsxs("p",{children:[e.jsx("strong",{className:"text-foreground",children:"注意:"}),"更换嵌入模型可能会影响知识库的匹配精度!"]}),e.jsxs("ul",{className:"space-y-2 ml-4 list-disc text-muted-foreground",children:[e.jsx("li",{children:"不同的嵌入模型会产生不同的向量表示"}),e.jsx("li",{children:"这可能导致现有知识库的检索结果不准确"}),e.jsx("li",{children:"建议更换嵌入模型后重新生成所有知识库的向量"})]}),e.jsx("p",{className:"text-foreground font-medium",children:"确定要更换嵌入模型吗?"})]})})]}),e.jsxs(fs,{children:[e.jsx(vs,{onClick:us,children:"取消"}),e.jsx(js,{onClick:as,className:"bg-amber-600 hover:bg-amber-700",children:"确认更换"})]})]})}),e.jsx(u4,{open:X,onOpenChange:L,value:C?.extra_params||{},onChange:ae=>R(oe=>oe?{...oe,extra_params:ae}:null)}),e.jsx(nr,{})]})})}const xc=Mj,hc=Aw,fc=zw,pd="/api/webui/config";async function D4(){const l=await(await ke(`${pd}/adapter-config/path`)).json();return!l.success||!l.path?null:{path:l.path,lastModified:l.lastModified}}async function Wg(a){const r=await(await ke(`${pd}/adapter-config/path`,{method:"POST",headers:Zs(),body:JSON.stringify({path:a})})).json();if(!r.success)throw new Error(r.message||"保存路径失败")}async function ej(a){const r=await(await ke(`${pd}/adapter-config?path=${encodeURIComponent(a)}`)).json();if(!r.success)throw new Error("读取配置文件失败");return r.content}async function sj(a,l){const c=await(await ke(`${pd}/adapter-config`,{method:"POST",headers:Zs(),body:JSON.stringify({path:a,content:l})})).json();if(!c.success)throw new Error(c.message||"保存配置失败")}const kt={inner:{version:"0.1.2"},nickname:{nickname:""},napcat_server:{host:"localhost",port:8095,token:"",heartbeat_interval:30},maibot_server:{host:"localhost",port:8e3},chat:{group_list_type:"whitelist",group_list:[],private_list_type:"whitelist",private_list:[],ban_user_id:[],ban_qq_bot:!1,enable_poke:!0},voice:{use_tts:!1},forward:{image_threshold:30},debug:{level:"INFO"}},Fm={oneclick:{name:"一键包",description:"使用一键包部署的适配器配置",path:"../MaiBot-Napcat-Adapter/config.toml",icon:xa},docker:{name:"Docker",description:"Docker Compose 部署的适配器配置",path:"/MaiMBot/adapters-config/config.toml",icon:B1}};function Hm(a){try{const l=_x(a);return{inner:{...kt.inner,...l.inner},nickname:{...kt.nickname,...l.nickname},napcat_server:{...kt.napcat_server,...l.napcat_server},maibot_server:{...kt.maibot_server,...l.maibot_server},chat:{...kt.chat,...l.chat},voice:{...kt.voice,...l.voice},forward:{...kt.forward,...l.forward},debug:{...kt.debug,...l.debug}}}catch(l){throw console.error("TOML 解析失败:",l),new Error(`无法解析 TOML 文件: ${l instanceof Error?l.message:"未知错误"}`)}}function qm(a){try{const l=(d,m)=>d===""||d===null||d===void 0?m:d,r={inner:{version:l(a.inner.version,kt.inner.version)},nickname:{nickname:l(a.nickname.nickname,kt.nickname.nickname)},napcat_server:{host:l(a.napcat_server.host,kt.napcat_server.host),port:l(a.napcat_server.port||0,kt.napcat_server.port),token:l(a.napcat_server.token,kt.napcat_server.token),heartbeat_interval:l(a.napcat_server.heartbeat_interval||0,kt.napcat_server.heartbeat_interval)},maibot_server:{host:l(a.maibot_server.host,kt.maibot_server.host),port:l(a.maibot_server.port||0,kt.maibot_server.port)},chat:{group_list_type:l(a.chat.group_list_type,kt.chat.group_list_type),group_list:a.chat.group_list||[],private_list_type:l(a.chat.private_list_type,kt.chat.private_list_type),private_list:a.chat.private_list||[],ban_user_id:a.chat.ban_user_id||[],ban_qq_bot:a.chat.ban_qq_bot??kt.chat.ban_qq_bot,enable_poke:a.chat.enable_poke??kt.chat.enable_poke},voice:{use_tts:a.voice.use_tts??kt.voice.use_tts},forward:{image_threshold:l(a.forward.image_threshold||0,kt.forward.image_threshold)},debug:{level:l(a.debug.level,kt.debug.level)}};let c=GS(r);return c=O4(c),c}catch(l){throw console.error("TOML 生成失败:",l),new Error(`无法生成 TOML 文件: ${l instanceof Error?l.message:"未知错误"}`)}}function O4(a){const l=a.split(` `),r=[];for(let c=0;c"|?*\x00-\x1F]/.test(a)?{valid:!1,error:"路径包含非法字符"}:{valid:!0,error:""}}function L4(){const[a,l]=u.useState("upload"),[r,c]=u.useState(null),[d,m]=u.useState(""),[h,f]=u.useState(""),[p,g]=u.useState("oneclick"),[N,j]=u.useState(""),[b,y]=u.useState(!1),[w,z]=u.useState(!1),[M,S]=u.useState(!1),[F,E]=u.useState(!1),[C,R]=u.useState(null),[H,O]=u.useState(!1),X=u.useRef(null),{toast:L}=nt(),me=u.useRef(null),Ne=A=>{if(f(A),A.trim()){const K=Vm(A);j(K.error)}else j("")},je=u.useCallback(async A=>{const K=Fm[A];z(!0);try{const Re=await ej(K.path),se=Hm(Re);c(se),g(A),f(K.path),await Wg(K.path),L({title:"加载成功",description:`已从${K.name}预设加载配置`})}catch(Re){console.error("加载预设配置失败:",Re),L({title:"加载失败",description:Re instanceof Error?Re.message:"无法读取预设配置文件",variant:"destructive"})}finally{z(!1)}},[L]),ce=u.useCallback(async A=>{const K=Vm(A);if(!K.valid){j(K.error),L({title:"路径无效",description:K.error,variant:"destructive"});return}j(""),z(!0);try{const Re=await ej(A),se=Hm(Re);c(se),f(A),await Wg(A),L({title:"加载成功",description:"已从配置文件加载"})}catch(Re){console.error("加载配置失败:",Re),L({title:"加载失败",description:Re instanceof Error?Re.message:"无法读取配置文件",variant:"destructive"})}finally{z(!1)}},[L]);u.useEffect(()=>{(async()=>{try{const K=await D4();if(K&&K.path){f(K.path);const Re=Object.entries(Fm).find(([,se])=>se.path===K.path);Re?(l("preset"),g(Re[0]),await je(Re[0])):(l("path"),await ce(K.path))}}catch(K){console.error("加载保存的路径失败:",K)}})()},[ce,je]);const ge=u.useCallback(A=>{a!=="path"&&a!=="preset"||!h||(me.current&&clearTimeout(me.current),me.current=setTimeout(async()=>{y(!0);try{const K=qm(A);await sj(h,K),L({title:"自动保存成功",description:"配置已保存到文件"})}catch(K){console.error("自动保存失败:",K),L({title:"自动保存失败",description:K instanceof Error?K.message:"保存配置失败",variant:"destructive"})}finally{y(!1)}},1e3))},[a,h,L]),pe=async()=>{if(!r||!h)return;const A=Vm(h);if(!A.valid){L({title:"保存失败",description:A.error,variant:"destructive"});return}y(!0);try{const K=qm(r);await sj(h,K),L({title:"保存成功",description:"配置已保存到文件"})}catch(K){console.error("保存失败:",K),L({title:"保存失败",description:K instanceof Error?K.message:"保存配置失败",variant:"destructive"})}finally{y(!1)}},D=async()=>{h&&await ce(h)},Q=A=>{if(A!==a){if(r){R(A),S(!0);return}B(A)}},B=A=>{c(null),m(""),j(""),l(A),A==="preset"&&je("oneclick"),L({title:"已切换模式",description:{upload:"现在可以上传配置文件",path:"现在可以指定配置文件路径",preset:"现在可以使用预设配置"}[A]})},ue=()=>{C&&(B(C),R(null)),S(!1)},Y=()=>{if(r){E(!0);return}we()},we=()=>{f(""),c(null),j(""),L({title:"已清空",description:"路径和配置已清空"})},fe=()=>{we(),E(!1)},Ee=A=>{const K=A.target.files?.[0];if(!K)return;const Re=new FileReader;Re.onload=se=>{try{const $e=se.target?.result,cs=Hm($e);c(cs),m(K.name),L({title:"上传成功",description:`已加载配置文件:${K.name}`})}catch($e){console.error("解析配置文件失败:",$e),L({title:"解析失败",description:"配置文件格式错误,请检查文件内容",variant:"destructive"})}},Re.readAsText(K)},G=()=>{if(!r)return;const A=qm(r),K=new Blob([A],{type:"text/plain;charset=utf-8"}),Re=URL.createObjectURL(K),se=document.createElement("a");se.href=Re,se.download=d||"config.toml",document.body.appendChild(se),se.click(),document.body.removeChild(se),URL.revokeObjectURL(Re),L({title:"下载成功",description:"配置文件已下载,请手动覆盖并重启适配器"})},$=()=>{c(JSON.parse(JSON.stringify(kt))),m("config.toml"),L({title:"已加载默认配置",description:"可以开始编辑配置"})};return e.jsx(ts,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsx("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"麦麦适配器配置"}),e.jsx("p",{className:"text-muted-foreground mt-1 sm:mt-2 text-sm sm:text-base",children:"管理麦麦的 QQ 适配器的配置文件"})]})}),e.jsx(xc,{open:H,onOpenChange:O,children:e.jsxs(Te,{children:[e.jsx(Oe,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(Ue,{children:"工作模式"}),e.jsx(Ns,{children:"选择配置文件的管理方式"})]}),e.jsx(hc,{asChild:!0,children:e.jsxs(_,{variant:"ghost",size:"sm",className:"w-9 p-0",children:[e.jsx(Ba,{className:`h-4 w-4 transition-transform duration-200 ${H?"transform rotate-180":""}`}),e.jsx("span",{className:"sr-only",children:"切换"})]})})]})}),e.jsx(fc,{children:e.jsxs(ze,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3 md:gap-4",children:[e.jsx("div",{className:`border-2 rounded-lg p-3 md:p-4 cursor-pointer transition-all ${a==="preset"?"border-primary bg-primary/5":"border-muted hover:border-primary/50 active:border-primary/70"}`,onClick:()=>Q("preset"),children:e.jsxs("div",{className:"flex items-start gap-2 md:gap-3",children:[e.jsx(xa,{className:"h-4 w-4 md:h-5 md:w-5 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"font-semibold text-sm md:text-base",children:"预设模式"}),e.jsx("p",{className:"text-xs md:text-sm text-muted-foreground mt-1 line-clamp-2",children:"使用预设的部署配置"})]})]})}),e.jsx("div",{className:`border-2 rounded-lg p-3 md:p-4 cursor-pointer transition-all ${a==="upload"?"border-primary bg-primary/5":"border-muted hover:border-primary/50 active:border-primary/70"}`,onClick:()=>Q("upload"),children:e.jsxs("div",{className:"flex items-start gap-2 md:gap-3",children:[e.jsx(cc,{className:"h-4 w-4 md:h-5 md:w-5 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"font-semibold text-sm md:text-base",children:"上传文件模式"}),e.jsx("p",{className:"text-xs md:text-sm text-muted-foreground mt-1 line-clamp-2",children:"上传配置文件,编辑后下载并手动覆盖"})]})]})}),e.jsx("div",{className:`border-2 rounded-lg p-3 md:p-4 cursor-pointer transition-all ${a==="path"?"border-primary bg-primary/5":"border-muted hover:border-primary/50 active:border-primary/70"}`,onClick:()=>Q("path"),children:e.jsxs("div",{className:"flex items-start gap-2 md:gap-3",children:[e.jsx(I1,{className:"h-4 w-4 md:h-5 md:w-5 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"font-semibold text-sm md:text-base",children:"指定路径模式"}),e.jsx("p",{className:"text-xs md:text-sm text-muted-foreground mt-1 line-clamp-2",children:"指定配置文件路径,自动加载和保存"})]})]})})]}),a==="preset"&&e.jsxs("div",{className:"space-y-3 pt-2 border-t",children:[e.jsx(T,{className:"text-sm md:text-base",children:"选择部署方式"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:Object.entries(Fm).map(([A,K])=>{const Re=K.icon,se=p===A;return e.jsx("div",{className:`border-2 rounded-lg p-3 cursor-pointer transition-all ${se?"border-primary bg-primary/5":"border-muted hover:border-primary/50"}`,onClick:()=>{g(A),je(A)},children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Re,{className:"h-5 w-5 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h4",{className:"font-semibold text-sm",children:K.name}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:K.description}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1 font-mono break-all",children:K.path})]})]})},A)})})]}),a==="path"&&e.jsxs("div",{className:"space-y-3 pt-2 border-t",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"config-path",className:"text-sm md:text-base",children:"配置文件路径"}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx(ne,{id:"config-path",value:h,onChange:A=>Ne(A.target.value),placeholder:"例: C:\\Adapter\\config.toml",className:`text-sm ${N?"border-destructive":""}`}),N&&e.jsx("p",{className:"text-xs text-destructive",children:N})]}),e.jsx(_,{onClick:()=>ce(h),disabled:w||!h||!!N,className:"w-full sm:w-auto",children:w?e.jsxs(e.Fragment,{children:[e.jsx(dt,{className:"h-4 w-4 animate-spin mr-2"}),e.jsx("span",{className:"sm:hidden",children:"加载中..."})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"sm:hidden",children:"加载配置"}),e.jsx("span",{className:"hidden sm:inline",children:"加载"})]})})]})]}),e.jsxs("details",{className:"rounded-lg bg-muted/50 p-3 group",children:[e.jsxs("summary",{className:"text-xs font-medium cursor-pointer select-none list-none flex items-center justify-between",children:[e.jsx("span",{children:"路径格式说明"}),e.jsx("svg",{className:"h-4 w-4 transition-transform group-open:rotate-180",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),e.jsxs("div",{className:"mt-2 space-y-2 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:"font-mono bg-background px-1.5 py-0.5 rounded text-[10px] md:text-xs whitespace-nowrap",children:"Windows"})}),e.jsxs("div",{className:"pl-2 space-y-0.5 text-[10px] md:text-xs break-all",children:[e.jsx("div",{children:"C:\\Adapter\\config.toml"}),e.jsx("div",{className:"hidden sm:block",children:"D:\\MaiBot\\adapter\\config.toml"}),e.jsx("div",{className:"hidden sm:block",children:"\\\\server\\share\\config.toml"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:"font-mono bg-background px-1.5 py-0.5 rounded text-[10px] md:text-xs whitespace-nowrap",children:"Linux"})}),e.jsxs("div",{className:"pl-2 space-y-0.5 text-[10px] md:text-xs break-all",children:[e.jsx("div",{children:"/opt/adapter/config.toml"}),e.jsx("div",{className:"hidden sm:block",children:"/home/user/adapter/config.toml"}),e.jsx("div",{className:"hidden sm:block",children:"~/adapter/config.toml"})]})]}),e.jsx("p",{className:"pt-1 border-t text-[10px] md:text-xs",children:"💡 配置会自动保存到指定文件,修改后 1 秒自动保存"})]})]})]})]})})]})}),e.jsxs(ht,{children:[e.jsx(Yt,{className:"h-4 w-4"}),e.jsx(ft,{children:a==="preset"?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"预设模式:"}),"选择预设的部署方式,配置会自动加载,修改后 1 秒自动保存",b&&" (正在保存...)"]}):a==="upload"?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"上传文件模式:"}),"上传配置文件 → 在线编辑 → 下载文件 → 手动覆盖并重启适配器"]}):e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"指定路径模式:"}),"指定配置文件路径后,配置会自动加载,修改后 1 秒自动保存",b&&" (正在保存...)"]})})]}),a==="upload"&&!r&&e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 w-full",children:[e.jsx("input",{ref:X,type:"file",accept:".toml",className:"hidden",onChange:Ee}),e.jsxs(_,{onClick:()=>X.current?.click(),size:"sm",variant:"outline",className:"w-full sm:w-auto",children:[e.jsx(cc,{className:"mr-2 h-4 w-4"}),"上传配置"]}),e.jsxs(_,{onClick:$,size:"sm",className:"w-full sm:w-auto",children:[e.jsx(Ua,{className:"mr-2 h-4 w-4"}),"使用默认配置"]})]}),a==="upload"&&r&&e.jsx("div",{className:"flex gap-2",children:e.jsxs(_,{onClick:G,size:"sm",className:"w-full sm:w-auto",children:[e.jsx(na,{className:"mr-2 h-4 w-4"}),"下载配置"]})}),(a==="preset"||a==="path")&&r&&e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsxs(_,{onClick:pe,size:"sm",disabled:b||!!N,className:"w-full sm:w-auto",children:[e.jsx(gc,{className:"mr-2 h-4 w-4"}),b?"保存中...":"立即保存"]}),e.jsxs(_,{onClick:D,size:"sm",variant:"outline",disabled:w,className:"w-full sm:w-auto",children:[e.jsx(dt,{className:`mr-2 h-4 w-4 ${w?"animate-spin":""}`}),"刷新"]}),a==="path"&&e.jsxs(_,{onClick:Y,size:"sm",variant:"destructive",className:"w-full sm:w-auto",children:[e.jsx(os,{className:"mr-2 h-4 w-4"}),"清空路径"]})]}),r?e.jsxs(Jt,{defaultValue:"napcat",className:"w-full",children:[e.jsx("div",{className:"overflow-x-auto -mx-4 px-4 sm:mx-0 sm:px-0",children:e.jsxs(Gt,{className:"inline-flex w-auto min-w-full sm:grid sm:w-full sm:grid-cols-5",children:[e.jsxs(Xe,{value:"napcat",className:"flex-shrink-0 text-xs sm:text-sm whitespace-nowrap",children:[e.jsx("span",{className:"hidden sm:inline",children:"Napcat 连接"}),e.jsx("span",{className:"sm:hidden",children:"Napcat"})]}),e.jsxs(Xe,{value:"maibot",className:"flex-shrink-0 text-xs sm:text-sm whitespace-nowrap",children:[e.jsx("span",{className:"hidden sm:inline",children:"麦麦连接"}),e.jsx("span",{className:"sm:hidden",children:"麦麦"})]}),e.jsxs(Xe,{value:"chat",className:"flex-shrink-0 text-xs sm:text-sm whitespace-nowrap",children:[e.jsx("span",{className:"hidden sm:inline",children:"聊天控制"}),e.jsx("span",{className:"sm:hidden",children:"聊天"})]}),e.jsxs(Xe,{value:"voice",className:"flex-shrink-0 text-xs sm:text-sm whitespace-nowrap",children:[e.jsx("span",{className:"hidden sm:inline",children:"语音与转发"}),e.jsx("span",{className:"sm:hidden",children:"语音"})]}),e.jsx(Xe,{value:"debug",className:"flex-shrink-0 text-xs sm:text-sm whitespace-nowrap",children:"调试"})]})}),e.jsx(Ss,{value:"napcat",className:"space-y-4",children:e.jsx(U4,{config:r,onChange:A=>{c(A),ge(A)}})}),e.jsx(Ss,{value:"maibot",className:"space-y-4",children:e.jsx($4,{config:r,onChange:A=>{c(A),ge(A)}})}),e.jsx(Ss,{value:"chat",className:"space-y-4",children:e.jsx(B4,{config:r,onChange:A=>{c(A),ge(A)}})}),e.jsx(Ss,{value:"voice",className:"space-y-4",children:e.jsx(I4,{config:r,onChange:A=>{c(A),ge(A)}})}),e.jsx(Ss,{value:"debug",className:"space-y-4",children:e.jsx(P4,{config:r,onChange:A=>{c(A),ge(A)}})})]}):e.jsx("div",{className:"rounded-lg border bg-card p-6 md:p-12",children:e.jsxs("div",{className:"text-center space-y-3 md:space-y-4",children:[e.jsx(Ua,{className:"h-12 w-12 md:h-16 md:w-16 mx-auto text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base md:text-lg font-semibold",children:"尚未加载配置"}),e.jsx("p",{className:"text-xs md:text-sm text-muted-foreground mt-2 px-4",children:a==="preset"?"请选择预设的部署方式":a==="upload"?"请上传现有配置文件,或使用默认配置开始编辑":"请指定配置文件路径并点击加载按钮"})]})]})}),e.jsx(bs,{open:M,onOpenChange:S,children:e.jsxs(xs,{children:[e.jsxs(hs,{children:[e.jsx(ps,{children:"确认切换模式"}),e.jsxs(gs,{children:["切换模式将清空当前配置,确定要继续吗?",e.jsx("br",{}),e.jsx("span",{className:"text-destructive font-medium",children:"请确保已保存重要配置"})]})]}),e.jsxs(fs,{children:[e.jsx(vs,{onClick:()=>{S(!1),R(null)},children:"取消"}),e.jsx(js,{onClick:ue,children:"确认切换"})]})]})}),e.jsx(bs,{open:F,onOpenChange:E,children:e.jsxs(xs,{children:[e.jsxs(hs,{children:[e.jsx(ps,{children:"确认清空路径"}),e.jsxs(gs,{children:["清空路径将清除当前配置,确定要继续吗?",e.jsx("br",{}),e.jsx("span",{className:"text-muted-foreground text-sm",children:"此操作不会删除配置文件,只是清除界面中的配置"})]})]}),e.jsxs(fs,{children:[e.jsx(vs,{onClick:()=>E(!1),children:"取消"}),e.jsx(js,{onClick:fe,className:"bg-destructive hover:bg-destructive/90",children:"确认清空"})]})]})})]})})}function U4({config:a,onChange:l}){return e.jsx("div",{className:"rounded-lg border bg-card p-4 md:p-6 space-y-4 md:space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-base md:text-lg font-semibold mb-3 md:mb-4",children:"Napcat WebSocket 服务设置"}),e.jsxs("div",{className:"grid gap-3 md:gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"napcat-host",className:"text-sm md:text-base",children:"主机地址"}),e.jsx(ne,{id:"napcat-host",value:a.napcat_server.host,onChange:r=>l({...a,napcat_server:{...a.napcat_server,host:r.target.value}}),placeholder:"localhost",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Napcat 设定的主机地址"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"napcat-port",className:"text-sm md:text-base",children:"端口"}),e.jsx(ne,{id:"napcat-port",type:"number",value:a.napcat_server.port||"",onChange:r=>l({...a,napcat_server:{...a.napcat_server,port:r.target.value?parseInt(r.target.value):0}}),placeholder:"8095",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Napcat 设定的端口(留空使用默认值 8095)"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"napcat-token",className:"text-sm md:text-base",children:"访问令牌(Token)"}),e.jsx(ne,{id:"napcat-token",type:"password",value:a.napcat_server.token,onChange:r=>l({...a,napcat_server:{...a.napcat_server,token:r.target.value}}),placeholder:"留空表示无需令牌",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Napcat 设定的访问令牌,若无则留空"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"napcat-heartbeat",className:"text-sm md:text-base",children:"心跳间隔(秒)"}),e.jsx(ne,{id:"napcat-heartbeat",type:"number",value:a.napcat_server.heartbeat_interval||"",onChange:r=>l({...a,napcat_server:{...a.napcat_server,heartbeat_interval:r.target.value?parseInt(r.target.value):0}}),placeholder:"30",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"与 Napcat 设置的心跳间隔保持一致(留空使用默认值 30)"})]})]})]})})}function $4({config:a,onChange:l}){return e.jsx("div",{className:"rounded-lg border bg-card p-4 md:p-6 space-y-4 md:space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-base md:text-lg font-semibold mb-3 md:mb-4",children:"麦麦 WebSocket 服务设置"}),e.jsxs("div",{className:"grid gap-3 md:gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"maibot-host",className:"text-sm md:text-base",children:"主机地址"}),e.jsx(ne,{id:"maibot-host",value:a.maibot_server.host,onChange:r=>l({...a,maibot_server:{...a.maibot_server,host:r.target.value}}),placeholder:"localhost",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"麦麦在 .env 文件中设置的 HOST 字段"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"maibot-port",className:"text-sm md:text-base",children:"端口"}),e.jsx(ne,{id:"maibot-port",type:"number",value:a.maibot_server.port||"",onChange:r=>l({...a,maibot_server:{...a.maibot_server,port:r.target.value?parseInt(r.target.value):0}}),placeholder:"8000",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"麦麦在 .env 文件中设置的 PORT 字段(留空使用默认值 8000)"})]})]})]})})}function B4({config:a,onChange:l}){const r=m=>{const h={...a};m==="group"?h.chat.group_list=[...h.chat.group_list,0]:m==="private"?h.chat.private_list=[...h.chat.private_list,0]:h.chat.ban_user_id=[...h.chat.ban_user_id,0],l(h)},c=(m,h)=>{const f={...a};m==="group"?f.chat.group_list=f.chat.group_list.filter((p,g)=>g!==h):m==="private"?f.chat.private_list=f.chat.private_list.filter((p,g)=>g!==h):f.chat.ban_user_id=f.chat.ban_user_id.filter((p,g)=>g!==h),l(f)},d=(m,h,f)=>{const p={...a};m==="group"?p.chat.group_list[h]=f:m==="private"?p.chat.private_list[h]=f:p.chat.ban_user_id[h]=f,l(p)};return e.jsx("div",{className:"rounded-lg border bg-card p-4 md:p-6 space-y-4 md:space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-base md:text-lg font-semibold mb-3 md:mb-4",children:"聊天黑白名单功能"}),e.jsxs("div",{className:"grid gap-4 md:gap-6",children:[e.jsxs("div",{className:"space-y-3 md:space-y-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{className:"text-sm md:text-base",children:"群组名单类型"}),e.jsxs(Pe,{value:a.chat.group_list_type,onValueChange:m=>l({...a,chat:{...a.chat,group_list_type:m}}),children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsxs(Ie,{children:[e.jsx(W,{value:"whitelist",children:"白名单(仅名单内可聊天)"}),e.jsx(W,{value:"blacklist",children:"黑名单(名单内禁止聊天)"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2 sm:gap-0",children:[e.jsx(T,{className:"text-sm md:text-base",children:"群组列表"}),e.jsxs(_,{onClick:()=>r("group"),size:"sm",variant:"outline",className:"w-full sm:w-auto",children:[e.jsx(Ua,{className:"mr-1 h-4 w-4"}),"添加群号"]})]}),a.chat.group_list.map((m,h)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ne,{type:"number",value:m,onChange:f=>d("group",h,parseInt(f.target.value)||0),placeholder:"输入群号",className:"text-sm md:text-base"}),e.jsxs(bs,{children:[e.jsx(wt,{asChild:!0,children:e.jsx(_,{size:"icon",variant:"outline",children:e.jsx(os,{className:"h-4 w-4"})})}),e.jsxs(xs,{children:[e.jsxs(hs,{children:[e.jsx(ps,{children:"确认删除"}),e.jsxs(gs,{children:["确定要删除群号 ",m," 吗?此操作无法撤销。"]})]}),e.jsxs(fs,{children:[e.jsx(vs,{children:"取消"}),e.jsx(js,{onClick:()=>c("group",h),children:"删除"})]})]})]})]},h)),a.chat.group_list.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"暂无群组"})]})]}),e.jsxs("div",{className:"space-y-3 md:space-y-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{className:"text-sm md:text-base",children:"私聊名单类型"}),e.jsxs(Pe,{value:a.chat.private_list_type,onValueChange:m=>l({...a,chat:{...a.chat,private_list_type:m}}),children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsxs(Ie,{children:[e.jsx(W,{value:"whitelist",children:"白名单(仅名单内可聊天)"}),e.jsx(W,{value:"blacklist",children:"黑名单(名单内禁止聊天)"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2 sm:gap-0",children:[e.jsx(T,{className:"text-sm md:text-base",children:"私聊列表"}),e.jsxs(_,{onClick:()=>r("private"),size:"sm",variant:"outline",className:"w-full sm:w-auto",children:[e.jsx(Ua,{className:"mr-1 h-4 w-4"}),"添加用户"]})]}),a.chat.private_list.map((m,h)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ne,{type:"number",value:m,onChange:f=>d("private",h,parseInt(f.target.value)||0),placeholder:"输入QQ号",className:"text-sm md:text-base"}),e.jsxs(bs,{children:[e.jsx(wt,{asChild:!0,children:e.jsx(_,{size:"icon",variant:"outline",children:e.jsx(os,{className:"h-4 w-4"})})}),e.jsxs(xs,{children:[e.jsxs(hs,{children:[e.jsx(ps,{children:"确认删除"}),e.jsxs(gs,{children:["确定要删除用户 ",m," 吗?此操作无法撤销。"]})]}),e.jsxs(fs,{children:[e.jsx(vs,{children:"取消"}),e.jsx(js,{onClick:()=>c("private",h),children:"删除"})]})]})]})]},h)),a.chat.private_list.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"暂无用户"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2 sm:gap-0",children:[e.jsxs("div",{children:[e.jsx(T,{className:"text-sm md:text-base",children:"全局禁止名单"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"名单中的用户无法进行任何聊天"})]}),e.jsxs(_,{onClick:()=>r("ban"),size:"sm",variant:"outline",className:"w-full sm:w-auto",children:[e.jsx(Ua,{className:"mr-1 h-4 w-4"}),"添加用户"]})]}),a.chat.ban_user_id.map((m,h)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ne,{type:"number",value:m,onChange:f=>d("ban",h,parseInt(f.target.value)||0),placeholder:"输入QQ号",className:"text-sm md:text-base"}),e.jsxs(bs,{children:[e.jsx(wt,{asChild:!0,children:e.jsx(_,{size:"icon",variant:"outline",children:e.jsx(os,{className:"h-4 w-4"})})}),e.jsxs(xs,{children:[e.jsxs(hs,{children:[e.jsx(ps,{children:"确认删除"}),e.jsxs(gs,{children:["确定要从全局禁止名单中删除用户 ",m," 吗?此操作无法撤销。"]})]}),e.jsxs(fs,{children:[e.jsx(vs,{children:"取消"}),e.jsx(js,{onClick:()=>c("ban",h),children:"删除"})]})]})]})]},h)),a.chat.ban_user_id.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"暂无禁止用户"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(T,{className:"text-sm md:text-base",children:"屏蔽QQ官方机器人"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"是否屏蔽来自QQ官方机器人的消息"})]}),e.jsx(Ge,{checked:a.chat.ban_qq_bot,onCheckedChange:m=>l({...a,chat:{...a.chat,ban_qq_bot:m}})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(T,{className:"text-sm md:text-base",children:"启用戳一戳功能"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"是否响应戳一戳消息"})]}),e.jsx(Ge,{checked:a.chat.enable_poke,onCheckedChange:m=>l({...a,chat:{...a.chat,enable_poke:m}})})]})]})]})})}function I4({config:a,onChange:l}){return e.jsxs("div",{className:"rounded-lg border bg-card p-4 md:p-6 space-y-4 md:space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base md:text-lg font-semibold mb-3 md:mb-4",children:"发送语音设置"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(T,{className:"text-sm md:text-base",children:"使用 TTS 语音"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"请确保已配置 TTS 并有对应的适配器"})]}),e.jsx(Ge,{checked:a.voice.use_tts,onCheckedChange:r=>l({...a,voice:{...a.voice,use_tts:r}})})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base md:text-lg font-semibold mb-3 md:mb-4",children:"转发消息处理设置"}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"image-threshold",className:"text-sm md:text-base",children:"图片数量阈值"}),e.jsx(ne,{id:"image-threshold",type:"number",value:a.forward.image_threshold||"",onChange:r=>l({...a,forward:{...a.forward,image_threshold:r.target.value?parseInt(r.target.value):0}}),placeholder:"30",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"转发消息中图片数量超过此值时使用占位符(避免麦麦VLM处理卡死)"})]})]})]})}function P4({config:a,onChange:l}){return e.jsx("div",{className:"rounded-lg border bg-card p-4 md:p-6 space-y-4 md:space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-base md:text-lg font-semibold mb-3 md:mb-4",children:"调试设置"}),e.jsx("div",{className:"grid gap-3 md:gap-4",children:e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{className:"text-sm md:text-base",children:"日志等级"}),e.jsxs(Pe,{value:a.debug.level,onValueChange:r=>l({...a,debug:{level:r}}),children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsxs(Ie,{children:[e.jsx(W,{value:"DEBUG",children:"DEBUG(调试)"}),e.jsx(W,{value:"INFO",children:"INFO(信息)"}),e.jsx(W,{value:"WARNING",children:"WARNING(警告)"}),e.jsx(W,{value:"ERROR",children:"ERROR(错误)"}),e.jsx(W,{value:"CRITICAL",children:"CRITICAL(严重)"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"设置适配器的日志输出等级"})]})})]})})}const F4=["defaultChecked","defaultValue","suppressContentEditableWarning","suppressHydrationWarning","dangerouslySetInnerHTML","accessKey","className","contentEditable","contextMenu","dir","draggable","hidden","id","lang","placeholder","slot","spellCheck","style","tabIndex","title","translate","radioGroup","role","about","datatype","inlist","prefix","property","resource","typeof","vocab","autoCapitalize","autoCorrect","autoSave","color","itemProp","itemScope","itemType","itemID","itemRef","results","security","unselectable","inputMode","is","onCopy","onCopyCapture","onCut","onCutCapture","onPaste","onPasteCapture","onCompositionEnd","onCompositionEndCapture","onCompositionStart","onCompositionStartCapture","onCompositionUpdate","onCompositionUpdateCapture","onFocus","onFocusCapture","onBlur","onBlurCapture","onChange","onChangeCapture","onBeforeInput","onBeforeInputCapture","onInput","onInputCapture","onReset","onResetCapture","onSubmit","onSubmitCapture","onInvalid","onInvalidCapture","onLoad","onLoadCapture","onError","onErrorCapture","onKeyDown","onKeyDownCapture","onKeyPress","onKeyPressCapture","onKeyUp","onKeyUpCapture","onAbort","onAbortCapture","onCanPlay","onCanPlayCapture","onCanPlayThrough","onCanPlayThroughCapture","onDurationChange","onDurationChangeCapture","onEmptied","onEmptiedCapture","onEncrypted","onEncryptedCapture","onEnded","onEndedCapture","onLoadedData","onLoadedDataCapture","onLoadedMetadata","onLoadedMetadataCapture","onLoadStart","onLoadStartCapture","onPause","onPauseCapture","onPlay","onPlayCapture","onPlaying","onPlayingCapture","onProgress","onProgressCapture","onRateChange","onRateChangeCapture","onSeeked","onSeekedCapture","onSeeking","onSeekingCapture","onStalled","onStalledCapture","onSuspend","onSuspendCapture","onTimeUpdate","onTimeUpdateCapture","onVolumeChange","onVolumeChangeCapture","onWaiting","onWaitingCapture","onAuxClick","onAuxClickCapture","onClick","onClickCapture","onContextMenu","onContextMenuCapture","onDoubleClick","onDoubleClickCapture","onDrag","onDragCapture","onDragEnd","onDragEndCapture","onDragEnter","onDragEnterCapture","onDragExit","onDragExitCapture","onDragLeave","onDragLeaveCapture","onDragOver","onDragOverCapture","onDragStart","onDragStartCapture","onDrop","onDropCapture","onMouseDown","onMouseDownCapture","onMouseEnter","onMouseLeave","onMouseMove","onMouseMoveCapture","onMouseOut","onMouseOutCapture","onMouseOver","onMouseOverCapture","onMouseUp","onMouseUpCapture","onSelect","onSelectCapture","onTouchCancel","onTouchCancelCapture","onTouchEnd","onTouchEndCapture","onTouchMove","onTouchMoveCapture","onTouchStart","onTouchStartCapture","onPointerDown","onPointerDownCapture","onPointerMove","onPointerMoveCapture","onPointerUp","onPointerUpCapture","onPointerCancel","onPointerCancelCapture","onPointerEnter","onPointerEnterCapture","onPointerLeave","onPointerLeaveCapture","onPointerOver","onPointerOverCapture","onPointerOut","onPointerOutCapture","onGotPointerCapture","onGotPointerCaptureCapture","onLostPointerCapture","onLostPointerCaptureCapture","onScroll","onScrollCapture","onWheel","onWheelCapture","onAnimationStart","onAnimationStartCapture","onAnimationEnd","onAnimationEndCapture","onAnimationIteration","onAnimationIterationCapture","onTransitionEnd","onTransitionEndCapture"],H4=/^(aria-|data-)/,oN=a=>Object.fromEntries(Object.entries(a).filter(([l])=>H4.test(l)||F4.includes(l)));function q4(a,l){const r=oN(a);return Object.keys(a).some(c=>!Object.hasOwn(r,c)&&a[c]!==l[c])}class V4 extends u.Component{container;plugin;componentDidMount(){this.installPlugin()}componentDidUpdate(l){if(l.uppy!==this.props.uppy)this.uninstallPlugin(l),this.installPlugin();else if(q4(this.props,l)){const{uppy:r,...c}={...this.props,target:this.container};this.plugin.setOptions(c)}}componentWillUnmount(){this.uninstallPlugin()}installPlugin(){const{uppy:l,...r}={id:"Dashboard",...this.props,inline:!0,target:this.container};l.use(v_,r),this.plugin=l.getPlugin(r.id)}uninstallPlugin(l=this.props){const{uppy:r}=l;r.removePlugin(this.plugin)}render(){return u.createElement("div",{className:"uppy-Container",ref:l=>{this.container=l},...oN(this.props)})}}function G4({src:a,alt:l="表情包",className:r,maxRetries:c=5,retryInterval:d=1500}){const[m,h]=u.useState("loading"),[f,p]=u.useState(0),[g,N]=u.useState(null),[j,b]=u.useState(a);a!==j&&(h("loading"),p(0),N(null),b(a));const y=u.useCallback(async()=>{try{const w=await fetch(a,{credentials:"include"});if(w.status===202){h("generating"),f{p(S=>S+1)},d):h("error");return}if(!w.ok){h("error");return}const z=await w.blob(),M=URL.createObjectURL(z);N(M),h("loaded")}catch(w){console.error("加载缩略图失败:",w),h("error")}},[a,f,c,d]);return u.useEffect(()=>{y()},[y]),u.useEffect(()=>()=>{g&&URL.revokeObjectURL(g)},[g]),m==="loading"||m==="generating"?e.jsx(ks,{className:P("w-full h-full",r)}):m==="error"||!g?e.jsx("div",{className:P("w-full h-full flex items-center justify-center bg-muted",r),children:e.jsx(xx,{className:"h-8 w-8 text-muted-foreground"})}):e.jsx("img",{src:g,alt:l,className:P("w-full h-full object-contain",r)})}function K4({children:a,className:l}){return e.jsx(bx,{content:a,className:l})}const al="/api/webui/emoji";async function Q4(a){const l=new URLSearchParams;a.page&&l.append("page",a.page.toString()),a.page_size&&l.append("page_size",a.page_size.toString()),a.search&&l.append("search",a.search),a.is_registered!==void 0&&l.append("is_registered",a.is_registered.toString()),a.is_banned!==void 0&&l.append("is_banned",a.is_banned.toString()),a.format&&l.append("format",a.format),a.sort_by&&l.append("sort_by",a.sort_by),a.sort_order&&l.append("sort_order",a.sort_order);const r=await ke(`${al}/list?${l}`,{});if(!r.ok)throw new Error(`获取表情包列表失败: ${r.statusText}`);return r.json()}async function Y4(a){const l=await ke(`${al}/${a}`,{});if(!l.ok)throw new Error(`获取表情包详情失败: ${l.statusText}`);return l.json()}async function J4(a,l){const r=await ke(`${al}/${a}`,{method:"PATCH",body:JSON.stringify(l)});if(!r.ok)throw new Error(`更新表情包失败: ${r.statusText}`);return r.json()}async function X4(a){const l=await ke(`${al}/${a}`,{method:"DELETE"});if(!l.ok)throw new Error(`删除表情包失败: ${l.statusText}`);return l.json()}async function Z4(){const a=await ke(`${al}/stats/summary`,{});if(!a.ok)throw new Error(`获取统计数据失败: ${a.statusText}`);return a.json()}async function W4(a){const l=await ke(`${al}/${a}/register`,{method:"POST"});if(!l.ok)throw new Error(`注册表情包失败: ${l.statusText}`);return l.json()}async function ek(a){const l=await ke(`${al}/${a}/ban`,{method:"POST"});if(!l.ok)throw new Error(`封禁表情包失败: ${l.statusText}`);return l.json()}function sk(a,l=!1){return l?`${al}/${a}/thumbnail?original=true`:`${al}/${a}/thumbnail`}function tk(a){return`${al}/${a}/thumbnail?original=true`}async function ak(a){const l=await ke(`${al}/batch/delete`,{method:"POST",body:JSON.stringify({emoji_ids:a})});if(!l.ok){const r=await l.json();throw new Error(r.detail||"批量删除失败")}return l.json()}function lk(){return`${al}/upload`}function nk(){const[a,l]=u.useState([]),[r,c]=u.useState(null),[d,m]=u.useState(!1),[h,f]=u.useState(1),[p,g]=u.useState(0),[N,j]=u.useState(20),[b,y]=u.useState("all"),[w,z]=u.useState("all"),[M,S]=u.useState("all"),[F,E]=u.useState("usage_count"),[C,R]=u.useState("desc"),[H,O]=u.useState(null),[X,L]=u.useState(!1),[me,Ne]=u.useState(!1),[je,ce]=u.useState(!1),[ge,pe]=u.useState(new Set),[D,Q]=u.useState(!1),[B,ue]=u.useState(""),[Y,we]=u.useState("medium"),[fe,Ee]=u.useState(!1),{toast:G}=nt(),$=u.useCallback(async()=>{try{m(!0);const xe=await Q4({page:h,page_size:N,is_registered:b==="all"?void 0:b==="registered",is_banned:w==="all"?void 0:w==="banned",format:M==="all"?void 0:M,sort_by:F,sort_order:C});l(xe.data),g(xe.total)}catch(xe){const Me=xe instanceof Error?xe.message:"加载表情包列表失败";G({title:"错误",description:Me,variant:"destructive"})}finally{m(!1)}},[h,N,b,w,M,F,C,G]),A=async()=>{try{const xe=await Z4();c(xe.data)}catch(xe){console.error("加载统计数据失败:",xe)}};u.useEffect(()=>{$()},[$]),u.useEffect(()=>{A()},[]);const K=async xe=>{try{const Me=await Y4(xe.id);O(Me.data),L(!0)}catch(Me){const ds=Me instanceof Error?Me.message:"加载详情失败";G({title:"错误",description:ds,variant:"destructive"})}},Re=xe=>{O(xe),Ne(!0)},se=xe=>{O(xe),ce(!0)},$e=async()=>{if(H)try{await X4(H.id),G({title:"成功",description:"表情包已删除"}),ce(!1),O(null),$(),A()}catch(xe){const Me=xe instanceof Error?xe.message:"删除失败";G({title:"错误",description:Me,variant:"destructive"})}},cs=async xe=>{try{await W4(xe.id),G({title:"成功",description:"表情包已注册"}),$(),A()}catch(Me){const ds=Me instanceof Error?Me.message:"注册失败";G({title:"错误",description:ds,variant:"destructive"})}},J=async xe=>{try{await ek(xe.id),G({title:"成功",description:"表情包已封禁"}),$(),A()}catch(Me){const ds=Me instanceof Error?Me.message:"封禁失败";G({title:"错误",description:ds,variant:"destructive"})}},Z=xe=>{const Me=new Set(ge);Me.has(xe)?Me.delete(xe):Me.add(xe),pe(Me)},Le=async()=>{try{const xe=await ak(Array.from(ge));G({title:"批量删除完成",description:xe.message}),pe(new Set),Q(!1),$(),A()}catch(xe){G({title:"批量删除失败",description:xe instanceof Error?xe.message:"批量删除失败",variant:"destructive"})}},le=()=>{const xe=parseInt(B),Me=Math.ceil(p/N);xe>=1&&xe<=Me?(f(xe),ue("")):G({title:"无效的页码",description:`请输入1-${Me}之间的页码`,variant:"destructive"})},De=r?.formats?Object.keys(r.formats):[];return e.jsxs("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:[e.jsxs("div",{className:"mb-4 sm:mb-6 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"表情包管理"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"管理麦麦的表情包资源"})]}),e.jsxs(_,{onClick:()=>Ee(!0),className:"gap-2",children:[e.jsx(cc,{className:"h-4 w-4"}),"上传表情包"]})]}),e.jsx(ts,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 pr-4",children:[r&&e.jsxs("div",{className:"grid gap-4 grid-cols-2 lg:grid-cols-4",children:[e.jsx(Te,{children:e.jsxs(Oe,{className:"pb-2",children:[e.jsx(Ns,{children:"总数"}),e.jsx(Ue,{className:"text-2xl",children:r.total})]})}),e.jsx(Te,{children:e.jsxs(Oe,{className:"pb-2",children:[e.jsx(Ns,{children:"已注册"}),e.jsx(Ue,{className:"text-2xl text-green-600",children:r.registered})]})}),e.jsx(Te,{children:e.jsxs(Oe,{className:"pb-2",children:[e.jsx(Ns,{children:"已封禁"}),e.jsx(Ue,{className:"text-2xl text-red-600",children:r.banned})]})}),e.jsx(Te,{children:e.jsxs(Oe,{className:"pb-2",children:[e.jsx(Ns,{children:"未注册"}),e.jsx(Ue,{className:"text-2xl text-gray-600",children:r.unregistered})]})})]}),e.jsxs(Te,{children:[e.jsx(Oe,{children:e.jsxs(Ue,{className:"flex items-center gap-2",children:[e.jsx(Po,{className:"h-5 w-5"}),"筛选和排序"]})}),e.jsxs(ze,{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"排序方式"}),e.jsxs(Pe,{value:`${F}-${C}`,onValueChange:xe=>{const[Me,ds]=xe.split("-");E(Me),R(ds),f(1)},children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsxs(Ie,{children:[e.jsx(W,{value:"usage_count-desc",children:"使用次数 (多→少)"}),e.jsx(W,{value:"usage_count-asc",children:"使用次数 (少→多)"}),e.jsx(W,{value:"register_time-desc",children:"注册时间 (新→旧)"}),e.jsx(W,{value:"register_time-asc",children:"注册时间 (旧→新)"}),e.jsx(W,{value:"record_time-desc",children:"记录时间 (新→旧)"}),e.jsx(W,{value:"record_time-asc",children:"记录时间 (旧→新)"}),e.jsx(W,{value:"last_used_time-desc",children:"最后使用 (新→旧)"}),e.jsx(W,{value:"last_used_time-asc",children:"最后使用 (旧→新)"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"注册状态"}),e.jsxs(Pe,{value:b,onValueChange:xe=>{y(xe),f(1)},children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsxs(Ie,{children:[e.jsx(W,{value:"all",children:"全部"}),e.jsx(W,{value:"registered",children:"已注册"}),e.jsx(W,{value:"unregistered",children:"未注册"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"封禁状态"}),e.jsxs(Pe,{value:w,onValueChange:xe=>{z(xe),f(1)},children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsxs(Ie,{children:[e.jsx(W,{value:"all",children:"全部"}),e.jsx(W,{value:"banned",children:"已封禁"}),e.jsx(W,{value:"unbanned",children:"未封禁"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"格式"}),e.jsxs(Pe,{value:M,onValueChange:xe=>{S(xe),f(1)},children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsxs(Ie,{children:[e.jsx(W,{value:"all",children:"全部"}),De.map(xe=>e.jsxs(W,{value:xe,children:[xe.toUpperCase()," (",r?.formats[xe],")"]},xe))]})]})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center justify-between gap-3 pt-4 border-t",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[ge.size>0&&e.jsxs("span",{className:"text-sm text-muted-foreground",children:["已选择 ",ge.size," 个表情包"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{className:"text-sm whitespace-nowrap",children:"卡片大小"}),e.jsxs(Pe,{value:Y,onValueChange:xe=>we(xe),children:[e.jsx(Be,{className:"w-24",children:e.jsx(Fe,{})}),e.jsxs(Ie,{children:[e.jsx(W,{value:"small",children:"小"}),e.jsx(W,{value:"medium",children:"中"}),e.jsx(W,{value:"large",children:"大"})]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{htmlFor:"emoji-page-size",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(Pe,{value:N.toString(),onValueChange:xe=>{j(parseInt(xe)),f(1),pe(new Set)},children:[e.jsx(Be,{id:"emoji-page-size",className:"w-20",children:e.jsx(Fe,{})}),e.jsxs(Ie,{children:[e.jsx(W,{value:"20",children:"20"}),e.jsx(W,{value:"40",children:"40"}),e.jsx(W,{value:"60",children:"60"}),e.jsx(W,{value:"100",children:"100"})]})]}),ge.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>pe(new Set),children:"取消选择"}),e.jsxs(_,{variant:"destructive",size:"sm",onClick:()=>Q(!0),children:[e.jsx(os,{className:"h-4 w-4 mr-1"}),"批量删除"]})]})]})]}),e.jsx("div",{className:"flex justify-end pt-4 border-t",children:e.jsxs(_,{variant:"outline",size:"sm",onClick:$,disabled:d,children:[e.jsx(dt,{className:`h-4 w-4 mr-2 ${d?"animate-spin":""}`}),"刷新"]})})]})]}),e.jsxs(Te,{children:[e.jsxs(Oe,{children:[e.jsx(Ue,{children:"表情包列表"}),e.jsxs(Ns,{children:["共 ",p," 个表情包,当前第 ",h," 页"]})]}),e.jsxs(ze,{children:[a.length===0?e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:"暂无数据"}):e.jsx("div",{className:`grid gap-3 ${Y==="small"?"grid-cols-3 sm:grid-cols-4 md:grid-cols-6 lg:grid-cols-8 xl:grid-cols-10":Y==="medium"?"grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-6 xl:grid-cols-8":"grid-cols-2 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5"}`,children:a.map(xe=>e.jsxs("div",{className:`group relative rounded-lg border bg-card overflow-hidden hover:ring-2 hover:ring-primary transition-all cursor-pointer ${ge.has(xe.id)?"ring-2 ring-primary bg-primary/5":""}`,onClick:()=>Z(xe.id),children:[e.jsx("div",{className:`absolute top-1 left-1 z-10 transition-opacity ${ge.has(xe.id)?"opacity-100":"opacity-0 group-hover:opacity-100"}`,children:e.jsx("div",{className:`w-5 h-5 rounded-full border-2 flex items-center justify-center ${ge.has(xe.id)?"bg-primary border-primary text-primary-foreground":"bg-background/80 border-muted-foreground/50"}`,children:ge.has(xe.id)&&e.jsx(st,{className:"h-3 w-3"})})}),e.jsxs("div",{className:"absolute top-1 right-1 z-10 flex flex-col gap-0.5",children:[xe.is_registered&&e.jsx(Ce,{variant:"default",className:"bg-green-600 text-[10px] px-1 py-0",children:"已注册"}),xe.is_banned&&e.jsx(Ce,{variant:"destructive",className:"text-[10px] px-1 py-0",children:"已封禁"})]}),e.jsx("div",{className:`aspect-square bg-muted flex items-center justify-center overflow-hidden ${Y==="small"?"p-1":Y==="medium"?"p-2":"p-3"}`,children:e.jsx(G4,{src:sk(xe.id),alt:"表情包"})}),e.jsxs("div",{className:`border-t bg-card ${Y==="small"?"p-1":"p-2"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-1 text-xs text-muted-foreground mb-1",children:[e.jsx(Ce,{variant:"outline",className:"text-[10px] px-1 py-0",children:xe.format.toUpperCase()}),e.jsxs("span",{className:"font-mono",children:[xe.usage_count,"次"]})]}),e.jsxs("div",{className:`flex gap-1 justify-center opacity-0 group-hover:opacity-100 transition-opacity ${Y==="small"?"flex-wrap":""}`,children:[e.jsx(_,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:Me=>{Me.stopPropagation(),Re(xe)},title:"编辑",children:e.jsx(sr,{className:"h-3 w-3"})}),e.jsx(_,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:Me=>{Me.stopPropagation(),K(xe)},title:"详情",children:e.jsx(Yt,{className:"h-3 w-3"})}),!xe.is_registered&&e.jsx(_,{variant:"ghost",size:"icon",className:"h-6 w-6 text-green-600 hover:text-green-700",onClick:Me=>{Me.stopPropagation(),cs(xe)},title:"注册",children:e.jsx(st,{className:"h-3 w-3"})}),!xe.is_banned&&e.jsx(_,{variant:"ghost",size:"icon",className:"h-6 w-6 text-orange-600 hover:text-orange-700",onClick:Me=>{Me.stopPropagation(),J(xe)},title:"封禁",children:e.jsx(iv,{className:"h-3 w-3"})}),e.jsx(_,{variant:"ghost",size:"icon",className:"h-6 w-6 text-red-600 hover:text-red-700",onClick:Me=>{Me.stopPropagation(),se(xe)},title:"删除",children:e.jsx(os,{className:"h-3 w-3"})})]})]})]},xe.id))}),p>0&&e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4 mt-4",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["显示 ",(h-1)*N+1," 到"," ",Math.min(h*N,p)," 条,共 ",p," 条"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>f(1),disabled:h===1,className:"hidden sm:flex",children:e.jsx(kn,{className:"h-4 w-4"})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>f(xe=>Math.max(1,xe-1)),disabled:h===1,children:[e.jsx(Pa,{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(ne,{type:"number",value:B,onChange:xe=>ue(xe.target.value),onKeyDown:xe=>xe.key==="Enter"&&le(),placeholder:h.toString(),className:"w-16 h-8 text-center",min:1,max:Math.ceil(p/N)}),e.jsx(_,{variant:"outline",size:"sm",onClick:le,disabled:!B,className:"h-8",children:"跳转"})]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>f(xe=>xe+1),disabled:h>=Math.ceil(p/N),children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(ra,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>f(Math.ceil(p/N)),disabled:h>=Math.ceil(p/N),className:"hidden sm:flex",children:e.jsx(Cn,{className:"h-4 w-4"})})]})]})]})]}),e.jsx(rk,{emoji:H,open:X,onOpenChange:L}),e.jsx(ik,{emoji:H,open:me,onOpenChange:Ne,onSuccess:()=>{$(),A()}}),e.jsx(ck,{open:fe,onOpenChange:Ee,onSuccess:()=>{$(),A()}})]})}),e.jsx(bs,{open:D,onOpenChange:Q,children:e.jsxs(xs,{children:[e.jsxs(hs,{children:[e.jsx(ps,{children:"确认批量删除"}),e.jsxs(gs,{children:["你确定要删除选中的 ",ge.size," 个表情包吗?此操作不可撤销。"]})]}),e.jsxs(fs,{children:[e.jsx(vs,{children:"取消"}),e.jsx(js,{onClick:Le,children:"确认删除"})]})]})}),e.jsx(Qs,{open:je,onOpenChange:ce,children:e.jsxs(Hs,{children:[e.jsxs(qs,{children:[e.jsx(Vs,{children:"确认删除"}),e.jsx(at,{children:"确定要删除这个表情包吗?此操作无法撤销。"})]}),e.jsxs(gt,{children:[e.jsx(_,{variant:"outline",onClick:()=>ce(!1),children:"取消"}),e.jsx(_,{variant:"destructive",onClick:$e,children:"删除"})]})]})})]})}function rk({emoji:a,open:l,onOpenChange:r}){if(!a)return null;const c=d=>d?new Date(d*1e3).toLocaleString("zh-CN"):"-";return e.jsx(Qs,{open:l,onOpenChange:r,children:e.jsxs(Hs,{className:"max-w-2xl max-h-[90vh]",children:[e.jsx(qs,{children:e.jsx(Vs,{children:"表情包详情"})}),e.jsx(ts,{className:"max-h-[calc(90vh-8rem)] pr-4",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"w-32 h-32 bg-muted rounded-lg flex items-center justify-center overflow-hidden",children:e.jsx("img",{src:tk(a.id),alt:a.description||"表情包",className:"w-full h-full object-cover",onError:d=>{const m=d.target;m.style.display="none";const h=m.parentElement;h&&(h.innerHTML='')}})})}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(T,{className:"text-muted-foreground",children:"ID"}),e.jsx("div",{className:"mt-1 font-mono",children:a.id})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-muted-foreground",children:"格式"}),e.jsx("div",{className:"mt-1",children:e.jsx(Ce,{variant:"outline",children:a.format.toUpperCase()})})]})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-muted-foreground",children:"文件路径"}),e.jsx("div",{className:"mt-1 font-mono text-sm break-all bg-muted p-2 rounded",children:a.full_path})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-muted-foreground",children:"哈希值"}),e.jsx("div",{className:"mt-1 font-mono text-sm break-all bg-muted p-2 rounded",children:a.emoji_hash})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-muted-foreground",children:"描述"}),a.description?e.jsx("div",{className:"mt-1 rounded-lg border bg-muted/50 p-3",children:e.jsx(K4,{className:"prose-sm",children:a.description})}):e.jsx("div",{className:"mt-1 text-sm text-muted-foreground",children:"-"})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-muted-foreground",children:"情绪"}),e.jsx("div",{className:"mt-1",children:a.emotion?e.jsx("span",{className:"text-sm",children:a.emotion}):e.jsx("span",{className:"text-sm text-muted-foreground",children:"-"})})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(T,{className:"text-muted-foreground",children:"状态"}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[a.is_registered&&e.jsx(Ce,{variant:"default",className:"bg-green-600",children:"已注册"}),a.is_banned&&e.jsx(Ce,{variant:"destructive",children:"已封禁"}),!a.is_registered&&!a.is_banned&&e.jsx(Ce,{variant:"outline",children:"未注册"})]})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-muted-foreground",children:"使用次数"}),e.jsx("div",{className:"mt-1 font-mono text-lg",children:a.usage_count})]})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(T,{className:"text-muted-foreground",children:"记录时间"}),e.jsx("div",{className:"mt-1 text-sm",children:c(a.record_time)})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-muted-foreground",children:"注册时间"}),e.jsx("div",{className:"mt-1 text-sm",children:c(a.register_time)})]})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-muted-foreground",children:"最后使用"}),e.jsx("div",{className:"mt-1 text-sm",children:c(a.last_used_time)})]})]})})]})})}function ik({emoji:a,open:l,onOpenChange:r,onSuccess:c}){const[d,m]=u.useState(""),[h,f]=u.useState(!1),[p,g]=u.useState(!1),[N,j]=u.useState(!1),{toast:b}=nt();u.useEffect(()=>{a&&(m(a.emotion||""),f(a.is_registered),g(a.is_banned))},[a]);const y=async()=>{if(a)try{j(!0);const w=d.split(/[,,]/).map(z=>z.trim()).filter(Boolean).join(",");await J4(a.id,{emotion:w||void 0,is_registered:h,is_banned:p}),b({title:"成功",description:"表情包信息已更新"}),r(!1),c()}catch(w){const z=w instanceof Error?w.message:"保存失败";b({title:"错误",description:z,variant:"destructive"})}finally{j(!1)}};return a?e.jsx(Qs,{open:l,onOpenChange:r,children:e.jsxs(Hs,{className:"max-w-2xl",children:[e.jsxs(qs,{children:[e.jsx(Vs,{children:"编辑表情包"}),e.jsx(at,{children:"修改表情包的情绪和状态信息"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(T,{children:"情绪"}),e.jsx(pt,{value:d,onChange:w=>m(w.target.value),placeholder:"输入情绪描述...",rows:2,className:"mt-1"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"输入情绪相关的文本描述"})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(tt,{id:"is_registered",checked:h,onCheckedChange:w=>{w===!0?(f(!0),g(!1)):f(!1)}}),e.jsx(T,{htmlFor:"is_registered",className:"cursor-pointer",children:"已注册"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(tt,{id:"is_banned",checked:p,onCheckedChange:w=>{w===!0?(g(!0),f(!1)):g(!1)}}),e.jsx(T,{htmlFor:"is_banned",className:"cursor-pointer",children:"已封禁"})]})]})]}),e.jsxs(gt,{children:[e.jsx(_,{variant:"outline",onClick:()=>r(!1),children:"取消"}),e.jsx(_,{onClick:y,disabled:N,children:N?"保存中...":"保存"})]})]})}):null}function ck({open:a,onOpenChange:l,onSuccess:r}){const[c,d]=u.useState("select"),[m,h]=u.useState([]),[f,p]=u.useState(null),[g,N]=u.useState(!1),{toast:j}=nt(),b=u.useMemo(()=>new N_({id:"emoji-uploader",autoProceed:!1,restrictions:{maxFileSize:10485760,allowedFileTypes:["image/jpeg","image/png","image/gif","image/webp"],maxNumberOfFiles:20},locale:{pluralize:()=>0,strings:{addMoreFiles:"添加更多文件",addingMoreFiles:"正在添加更多文件",allowedFileTypes:"允许的文件类型:%{types}",cancel:"取消",closeModal:"关闭",complete:"完成",connectedToInternet:"已连接到互联网",copyLink:"复制链接",copyLinkToClipboardFallback:"复制下方链接",copyLinkToClipboardSuccess:"链接已复制到剪贴板",dashboardTitle:"选择文件",dashboardWindowTitle:"文件选择窗口(按 ESC 关闭)",done:"完成",dropHereOr:"拖放文件到这里或 %{browse}",dropHint:"将文件拖放到此处",dropPasteFiles:"将文件拖放到这里或 %{browseFiles}",dropPasteFolders:"将文件拖放到这里或 %{browseFolders}",dropPasteBoth:"将文件拖放到这里,%{browseFiles} 或 %{browseFolders}",dropPasteImportFiles:"将文件拖放到这里,%{browseFiles} 或从以下位置导入:",dropPasteImportFolders:"将文件拖放到这里,%{browseFolders} 或从以下位置导入:",dropPasteImportBoth:"将文件拖放到这里,%{browseFiles},%{browseFolders} 或从以下位置导入:",editFile:"编辑文件",editing:"正在编辑 %{file}",emptyFolderAdded:"未从空文件夹添加文件",exceedsSize:"%{file} 超过了最大允许大小 %{size}",failedToUpload:"上传 %{file} 失败",fileSource:"文件来源:%{name}",filesUploadedOfTotal:{0:"已上传 %{complete} / %{smart_count} 个文件",1:"已上传 %{complete} / %{smart_count} 个文件"},filter:"筛选",finishEditingFile:"完成编辑文件",folderAdded:{0:"已从 %{folder} 添加 %{smart_count} 个文件",1:"已从 %{folder} 添加 %{smart_count} 个文件"},generatingThumbnails:"正在生成缩略图...",import:"导入",importFiles:"从以下位置导入文件:",importFrom:"从 %{name} 导入",loading:"加载中...",logOut:"登出",myDevice:"我的设备",noFilesFound:"这里没有文件或文件夹",noInternetConnection:"无网络连接",openFolderNamed:"打开文件夹 %{name}",pause:"暂停",pauseUpload:"暂停上传",paused:"已暂停",poweredBy:"技术支持:%{uppy}",processingXFiles:{0:"正在处理 %{smart_count} 个文件",1:"正在处理 %{smart_count} 个文件"},recording:"录制中",removeFile:"移除文件",resetFilter:"重置筛选",resume:"继续",resumeUpload:"继续上传",retry:"重试",retryUpload:"重试上传",save:"保存",saveChanges:"保存更改",selectFileNamed:"选择文件 %{name}",selectX:{0:"选择 %{smart_count}",1:"选择 %{smart_count}"},smile:"笑一个!",startRecording:"开始录制视频",stopRecording:"停止录制视频",takePicture:"拍照",timedOut:"上传已停滞 %{seconds} 秒,正在中止。",upload:"下一步",uploadComplete:"上传完成",uploadFailed:"上传失败",uploadPaused:"上传已暂停",uploadXFiles:{0:"下一步(%{smart_count} 个文件)",1:"下一步(%{smart_count} 个文件)"},uploadXNewFiles:{0:"下一步(+%{smart_count} 个文件)",1:"下一步(+%{smart_count} 个文件)"},uploading:"正在上传",uploadingXFiles:{0:"正在上传 %{smart_count} 个文件",1:"正在上传 %{smart_count} 个文件"},xFilesSelected:{0:"已选择 %{smart_count} 个文件",1:"已选择 %{smart_count} 个文件"},xMoreFilesAdded:{0:"又添加了 %{smart_count} 个文件",1:"又添加了 %{smart_count} 个文件"},xTimeLeft:"剩余 %{time}",youCanOnlyUploadFileTypes:"您只能上传:%{types}",youCanOnlyUploadX:{0:"您只能上传 %{smart_count} 个文件",1:"您只能上传 %{smart_count} 个文件"},youHaveToAtLeastSelectX:{0:"您至少需要选择 %{smart_count} 个文件",1:"您至少需要选择 %{smart_count} 个文件"},browseFiles:"浏览文件",browseFolders:"浏览文件夹",cancelUpload:"取消上传",addMore:"添加更多",back:"返回",editFileWithFilename:"编辑文件 %{file}"}}}),[]);u.useEffect(()=>{const H=()=>{const O=b.getFiles();if(O.length===0)return;const X=O.map(L=>({id:L.id,name:L.name,previewUrl:L.preview||URL.createObjectURL(L.data),emotion:"",description:"",isRegistered:!0,file:L.data}));h(X),O.length===1?(p(X[0].id),d("edit-single")):d("edit-multiple")};return b.on("upload",H),()=>{b.off("upload",H)}},[b]),u.useEffect(()=>{a||(b.cancelAll(),d("select"),h([]),p(null),N(!1))},[a,b]);const y=u.useCallback((H,O)=>{h(X=>X.map(L=>L.id===H?{...L,...O}:L))},[]),w=u.useCallback(H=>H.emotion.trim().length>0,[]),z=u.useMemo(()=>m.length>0&&m.every(w),[m,w]),M=u.useMemo(()=>m.find(H=>H.id===f)||null,[m,f]),S=u.useCallback(()=>{(c==="edit-single"||c==="edit-multiple")&&(d("select"),h([]),p(null))},[c]),F=u.useCallback(async()=>{if(!z){j({title:"请填写必填项",description:"每个表情包的情感标签都是必填的",variant:"destructive"});return}N(!0);let H=0,O=0;try{for(const X of m){const L=new FormData;L.append("file",X.file),L.append("emotion",X.emotion),L.append("description",X.description),L.append("is_registered",X.isRegistered.toString());try{(await ke(lk(),{method:"POST",body:L})).ok?H++:O++}catch{O++}}O===0?(j({title:"上传成功",description:`成功上传 ${H} 个表情包`}),l(!1),r()):(j({title:"部分上传失败",description:`成功 ${H} 个,失败 ${O} 个`,variant:"destructive"}),r())}finally{N(!1)}},[z,m,j,l,r]),E=()=>e.jsx("div",{className:"space-y-4",children:e.jsx("div",{className:"border rounded-lg overflow-hidden w-full",children:e.jsx(V4,{uppy:b,proudlyDisplayPoweredByUppy:!1,hideProgressDetails:!0,height:350,width:"100%",theme:"auto",note:"支持 JPG、PNG、GIF、WebP 格式,最多 20 个文件"})})}),C=()=>{const H=m[0];return H?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(_,{variant:"ghost",size:"sm",onClick:S,children:[e.jsx($a,{className:"h-4 w-4 mr-1"}),"返回"]}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"编辑表情包信息"})]}),e.jsxs("div",{className:"flex gap-6",children:[e.jsxs("div",{className:"flex-shrink-0",children:[e.jsx("div",{className:"w-32 h-32 rounded-lg border overflow-hidden bg-muted flex items-center justify-center",children:e.jsx("img",{src:H.previewUrl,alt:H.name,className:"max-w-full max-h-full object-contain"})}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2 text-center truncate max-w-32",children:H.name})]}),e.jsxs("div",{className:"flex-1 space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T,{htmlFor:"single-emotion",children:["情感标签 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(ne,{id:"single-emotion",value:H.emotion,onChange:O=>y(H.id,{emotion:O.target.value}),placeholder:"多个标签用逗号分隔,如:开心,高兴",className:H.emotion.trim()?"":"border-destructive"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"用于情感匹配,多个标签用逗号分隔"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"single-description",children:"描述"}),e.jsx(ne,{id:"single-description",value:H.description,onChange:O=>y(H.id,{description:O.target.value}),placeholder:"输入表情包描述..."})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(tt,{id:"single-is-registered",checked:H.isRegistered,onCheckedChange:O=>y(H.id,{isRegistered:O===!0})}),e.jsx(T,{htmlFor:"single-is-registered",className:"cursor-pointer",children:"上传后立即注册(可被麦麦使用)"})]})]})]}),e.jsx(gt,{children:e.jsx(_,{onClick:F,disabled:!z||g,children:g?"上传中...":"上传"})})]}):null},R=()=>{const H=m.filter(w).length,O=m.length;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(_,{variant:"ghost",size:"sm",onClick:S,children:[e.jsx($a,{className:"h-4 w-4 mr-1"}),"返回"]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["编辑表情包信息(",H,"/",O," 已完成)"]})]}),e.jsx(Ce,{variant:z?"default":"secondary",children:z?e.jsxs(e.Fragment,{children:[e.jsx(Ot,{className:"h-3 w-3 mr-1"}),"全部完成"]}):e.jsxs(e.Fragment,{children:[e.jsx(Sa,{className:"h-3 w-3 mr-1"}),"未完成"]})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(ts,{className:"h-[350px] pr-2",children:e.jsx("div",{className:"space-y-2",children:m.map(X=>{const L=w(X),me=f===X.id;return e.jsxs("div",{onClick:()=>p(X.id),className:` flex items-center gap-3 p-3 rounded-lg border-2 cursor-pointer transition-all @@ -77,7 +77,7 @@ Checking pack provider: ${f.name}`),console.log(` Pack URL: ${f.base_url}`),con ${L?"border-green-500 bg-green-50 dark:bg-green-950/20":"border-border hover:border-muted-foreground/50"} `,children:[e.jsx("div",{className:"w-12 h-12 rounded border overflow-hidden bg-muted flex-shrink-0 flex items-center justify-center",children:e.jsx("img",{src:X.previewUrl,alt:X.name,className:"max-w-full max-h-full object-contain"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:X.name}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:X.emotion||"未填写情感标签"})]}),L?e.jsx(st,{className:"h-5 w-5 text-green-500 flex-shrink-0"}):e.jsx("div",{className:"h-5 w-5 rounded-full border-2 border-muted-foreground/30 flex-shrink-0"})]},X.id)})})}),e.jsx("div",{className:"border rounded-lg p-4",children:M?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:M.previewUrl,alt:M.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:M.name}),w(M)&&e.jsxs(Ce,{variant:"outline",className:"text-green-600 border-green-600",children:[e.jsx(Ot,{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(ne,{id:"multi-emotion",value:M.emotion,onChange:X=>y(M.id,{emotion:X.target.value}),placeholder:"多个标签用逗号分隔,如:开心,高兴",className:M.emotion.trim()?"":"border-destructive"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"multi-description",children:"描述"}),e.jsx(ne,{id:"multi-description",value:M.description,onChange:X=>y(M.id,{description:X.target.value}),placeholder:"输入表情包描述..."})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(tt,{id:"multi-is-registered",checked:M.isRegistered,onCheckedChange:X=>y(M.id,{isRegistered:X===!0})}),e.jsx(T,{htmlFor:"multi-is-registered",className:"cursor-pointer text-sm",children:"上传后立即注册"})]})]}):e.jsx("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:e.jsxs("div",{className:"text-center",children:[e.jsx(xx,{className:"h-12 w-12 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:"点击左侧卡片编辑"})]})})})]}),e.jsx(gt,{children:e.jsx(_,{onClick:F,disabled:!z||g,children:g?"上传中...":`上传全部 (${O})`})})]})};return e.jsx(Qs,{open:a,onOpenChange:l,children:e.jsxs(Hs,{className:"max-w-3xl max-h-[90vh] overflow-hidden",children:[e.jsxs(qs,{children:[e.jsxs(Vs,{className:"flex items-center gap-2",children:[e.jsx(cc,{className:"h-5 w-5"}),c==="select"&&"上传表情包 - 选择文件",c==="edit-single"&&"上传表情包 - 填写信息",c==="edit-multiple"&&"上传表情包 - 批量编辑"]}),e.jsxs(at,{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"&&R()]})]})})}function ok(){const[a,l]=u.useState([]),[r,c]=u.useState(!0),[d,m]=u.useState(0),[h,f]=u.useState(1),[p,g]=u.useState(20),[N,j]=u.useState(""),[b,y]=u.useState(null),[w,z]=u.useState(!1),[M,S]=u.useState(!1),[F,E]=u.useState(!1),[C,R]=u.useState(null),[H,O]=u.useState(new Set),[X,L]=u.useState(!1),[me,Ne]=u.useState(""),[je,ce]=u.useState({total:0,recent_7days:0,chat_count:0,top_chats:{}}),[ge,pe]=u.useState([]),[D,Q]=u.useState(new Map),[B,ue]=u.useState(!1),[Y,we]=u.useState(0),{toast:fe}=nt(),Ee=async()=>{try{c(!0);const le=await a2({page:h,page_size:p,search:N||void 0});l(le.data),m(le.total)}catch(le){fe({title:"加载失败",description:le instanceof Error?le.message:"无法加载表达方式",variant:"destructive"})}finally{c(!1)}},G=async()=>{try{const le=await o2();le?.data&&ce(le.data)}catch(le){console.error("加载统计数据失败:",le)}},$=async()=>{try{const le=await jx();we(le.unchecked)}catch(le){console.error("加载审核统计失败:",le)}},A=async()=>{try{const le=await gx();if(le?.data){pe(le.data);const De=new Map;le.data.forEach(xe=>{De.set(xe.chat_id,xe.chat_name)}),Q(De)}}catch(le){console.error("加载聊天列表失败:",le)}},K=le=>D.get(le)||le;u.useEffect(()=>{Ee(),$(),G(),A()},[h,p,N]);const Re=async le=>{try{const De=await l2(le.id);y(De.data),z(!0)}catch(De){fe({title:"加载详情失败",description:De instanceof Error?De.message:"无法加载表达方式详情",variant:"destructive"})}},se=le=>{y(le),S(!0)},$e=async le=>{try{await i2(le.id),fe({title:"删除成功",description:`已删除表达方式: ${le.situation}`}),R(null),Ee(),G()}catch(De){fe({title:"删除失败",description:De instanceof Error?De.message:"无法删除表达方式",variant:"destructive"})}},cs=le=>{const De=new Set(H);De.has(le)?De.delete(le):De.add(le),O(De)},J=()=>{H.size===a.length&&a.length>0?O(new Set):O(new Set(a.map(le=>le.id)))},Z=async()=>{try{await c2(Array.from(H)),fe({title:"批量删除成功",description:`已删除 ${H.size} 个表达方式`}),O(new Set),L(!1),Ee(),G()}catch(le){fe({title:"批量删除失败",description:le instanceof Error?le.message:"无法批量删除表达方式",variant:"destructive"})}},Le=()=>{const le=parseInt(me),De=Math.ceil(d/p);le>=1&&le<=De?(f(le),Ne("")):fe({title:"无效的页码",description:`请输入1-${De}之间的页码`,variant:"destructive"})};return e.jsxs("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:[e.jsx("div",{className:"mb-4 sm:mb-6",children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl sm:text-3xl font-bold flex items-center gap-2",children:[e.jsx(Ia,{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(cv,{className:"h-4 w-4"}),"人工审核",Y>0&&e.jsx("span",{className:"ml-1 px-1.5 py-0.5 text-xs rounded-full bg-orange-500 text-white",children:Y>99?"99+":Y})]}),e.jsxs(_,{onClick:()=>E(!0),className:"gap-2",children:[e.jsx(Xs,{className:"h-4 w-4"}),"新增表达方式"]})]})]})}),e.jsx(ts,{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($t,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(ne,{id:"search",placeholder:"搜索情境、风格或上下文...",value:N,onChange:le=>j(le.target.value),className:"pl-9"})]})}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center justify-between gap-3 mt-4 pt-4 border-t",children:[e.jsx("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children: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(Pe,{value:p.toString(),onValueChange:le=>{g(parseInt(le)),f(1),O(new Set)},children:[e.jsx(Be,{id:"page-size",className:"w-20",children:e.jsx(Fe,{})}),e.jsxs(Ie,{children:[e.jsx(W,{value:"10",children:"10"}),e.jsx(W,{value:"20",children:"20"}),e.jsx(W,{value:"50",children:"50"}),e.jsx(W,{value:"100",children:"100"})]})]}),H.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>O(new Set),children:"取消选择"}),e.jsxs(_,{variant:"destructive",size:"sm",onClick:()=>L(!0),children:[e.jsx(os,{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(ql,{children:[e.jsx(Vl,{children:e.jsxs(_t,{children:[e.jsx(ns,{className:"w-12",children:e.jsx(tt,{checked:H.size===a.length&&a.length>0,onCheckedChange:J})}),e.jsx(ns,{children:"情境"}),e.jsx(ns,{children:"风格"}),e.jsx(ns,{children:"聊天"}),e.jsx(ns,{className:"text-right",children:"操作"})]})}),e.jsx(Gl,{children:r?e.jsx(_t,{children:e.jsx(Ze,{colSpan:5,className:"text-center py-8 text-muted-foreground",children:"加载中..."})}):a.length===0?e.jsx(_t,{children:e.jsx(Ze,{colSpan:5,className:"text-center py-8 text-muted-foreground",children:"暂无数据"})}):a.map(le=>e.jsxs(_t,{children:[e.jsx(Ze,{children:e.jsx(tt,{checked:H.has(le.id),onCheckedChange:()=>cs(le.id)})}),e.jsx(Ze,{className:"font-medium max-w-xs truncate",children:le.situation}),e.jsx(Ze,{className:"max-w-xs truncate",children:le.style}),e.jsx(Ze,{className:"max-w-[200px] truncate",title:K(le.chat_id),style:{wordBreak:"keep-all"},children:e.jsx("span",{className:"whitespace-nowrap overflow-hidden text-ellipsis block",children:K(le.chat_id)})}),e.jsx(Ze,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(_,{variant:"default",size:"sm",onClick:()=>se(le),children:[e.jsx(sr,{className:"h-4 w-4 mr-1"}),"编辑"]}),e.jsx(_,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>Re(le),title:"查看详情",children:e.jsx(ua,{className:"h-4 w-4"})}),e.jsxs(_,{size:"sm",onClick:()=>R(le),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(os,{className:"h-4 w-4 mr-1"}),"删除"]})]})})]},le.id))})]})}),e.jsx("div",{className:"md:hidden space-y-3 p-4",children:r?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):a.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无数据"}):a.map(le=>e.jsxs("div",{className:"rounded-lg border bg-card p-4 space-y-3 overflow-hidden",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(tt,{checked:H.has(le.id),onCheckedChange:()=>cs(le.id),className:"mt-1"}),e.jsxs("div",{className:"min-w-0 flex-1 overflow-hidden space-y-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"情境"}),e.jsx("h3",{className:"font-semibold text-sm line-clamp-2 w-full break-all",title:le.situation,children:le.situation})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"风格"}),e.jsx("p",{className:"text-sm line-clamp-2 w-full break-all",title:le.style,children:le.style})]})]})]}),e.jsxs("div",{className:"text-sm",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"聊天"}),e.jsx("p",{className:"text-sm truncate",title:K(le.chat_id),style:{wordBreak:"keep-all"},children:K(le.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:()=>se(le),className:"text-xs px-2 py-1 h-auto flex-shrink-0",children:[e.jsx(sr,{className:"h-3 w-3 mr-1"}),"编辑"]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>Re(le),className:"text-xs px-2 py-1 h-auto flex-shrink-0",children:e.jsx(ua,{className:"h-3 w-3"})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>R(le),className:"text-xs px-2 py-1 h-auto flex-shrink-0 text-destructive hover:text-destructive",children:[e.jsx(os,{className:"h-3 w-3 mr-1"}),"删除"]})]})]},le.id))}),d>0&&e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4 px-4 py-3 border-t",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["共 ",d," 条记录,第 ",h," / ",Math.ceil(d/p)," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>f(1),disabled:h===1,className:"hidden sm:flex",children:e.jsx(kn,{className:"h-4 w-4"})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>f(h-1),disabled:h===1,children:[e.jsx(Pa,{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(ne,{type:"number",value:me,onChange:le=>Ne(le.target.value),onKeyDown:le=>le.key==="Enter"&&Le(),placeholder:h.toString(),className:"w-16 h-8 text-center",min:1,max:Math.ceil(d/p)}),e.jsx(_,{variant:"outline",size:"sm",onClick:Le,disabled:!me,className:"h-8",children:"跳转"})]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>f(h+1),disabled:h>=Math.ceil(d/p),children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(ra,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>f(Math.ceil(d/p)),disabled:h>=Math.ceil(d/p),className:"hidden sm:flex",children:e.jsx(Cn,{className:"h-4 w-4"})})]})]})]})]})}),e.jsx(dk,{expression:b,open:w,onOpenChange:z,chatNameMap:D}),e.jsx(uk,{open:F,onOpenChange:E,chatList:ge,onSuccess:()=>{Ee(),G(),E(!1)}}),e.jsx(mk,{expression:b,open:M,onOpenChange:S,chatList:ge,onSuccess:()=>{Ee(),G(),S(!1)}}),e.jsx(bs,{open:!!C,onOpenChange:()=>R(null),children:e.jsxs(xs,{children:[e.jsxs(hs,{children:[e.jsx(ps,{children:"确认删除"}),e.jsxs(gs,{children:['确定要删除表达方式 "',C?.situation,'" 吗? 此操作不可撤销。']})]}),e.jsxs(fs,{children:[e.jsx(vs,{children:"取消"}),e.jsx(js,{onClick:()=>C&&$e(C),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"删除"})]})]})}),e.jsx(xk,{open:X,onOpenChange:L,onConfirm:Z,count:H.size}),e.jsx(Pv,{open:B,onOpenChange:le=>{ue(le),le||(Ee(),G(),$())}})]})}function dk({expression:a,open:l,onOpenChange:r,chatNameMap:c}){if(!a)return null;const d=h=>h?new Date(h*1e3).toLocaleString("zh-CN"):"-",m=h=>c.get(h)||h;return e.jsx(Qs,{open:l,onOpenChange:r,children:e.jsxs(Hs,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(qs,{children:[e.jsx(Vs,{children:"表达方式详情"}),e.jsx(at,{children:"查看表达方式的完整信息"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(Yi,{label:"情境",value:a.situation}),e.jsx(Yi,{label:"风格",value:a.style}),e.jsx(Yi,{label:"聊天",value:m(a.chat_id)}),e.jsx(Yi,{icon:Wr,label:"记录ID",value:a.id.toString(),mono:!0})]}),e.jsx("div",{className:"grid grid-cols-2 gap-4",children:e.jsx(Yi,{icon:da,label:"创建时间",value:d(a.create_date)})}),e.jsxs("div",{className:"rounded-lg border bg-muted/50 p-4",children:[e.jsx(T,{className:"text-xs text-muted-foreground mb-3 block",children:"状态标记"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:P("flex h-8 w-8 items-center justify-center rounded-full",a.checked?"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400":"bg-gray-100 text-gray-400 dark:bg-gray-800 dark:text-gray-600"),children:a.checked?e.jsx(st,{className:"h-5 w-5"}):e.jsx(Vo,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"已检查"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a.checked?"已通过审核":"未审核"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:P("flex h-8 w-8 items-center justify-center rounded-full",a.rejected?"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400":"bg-gray-100 text-gray-400 dark:bg-gray-800 dark:text-gray-600"),children:a.rejected?e.jsx(ta,{className:"h-5 w-5"}):e.jsx(Vo,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"已拒绝"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a.rejected?"不会被使用":"正常"})]})]})]})]})]}),e.jsx(gt,{children:e.jsx(_,{onClick:()=>r(!1),children:"关闭"})})]})})}function Yi({icon:a,label:l,value:r,mono:c=!1}){return e.jsxs("div",{className:"space-y-1",children:[e.jsxs(T,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[a&&e.jsx(a,{className:"h-3 w-3"}),l]}),e.jsx("div",{className:P("text-sm",c&&"font-mono",!r&&"text-muted-foreground"),children:r||"-"})]})}function uk({open:a,onOpenChange:l,chatList:r,onSuccess:c}){const[d,m]=u.useState({situation:"",style:"",chat_id:""}),[h,f]=u.useState(!1),{toast:p}=nt(),g=async()=>{if(!d.situation||!d.style||!d.chat_id){p({title:"验证失败",description:"请填写必填字段:情境、风格和聊天",variant:"destructive"});return}try{f(!0),await n2(d),p({title:"创建成功",description:"表达方式已创建"}),m({situation:"",style:"",chat_id:""}),c()}catch(N){p({title:"创建失败",description:N instanceof Error?N.message:"无法创建表达方式",variant:"destructive"})}finally{f(!1)}};return e.jsx(Qs,{open:a,onOpenChange:l,children:e.jsxs(Hs,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(qs,{children:[e.jsx(Vs,{children:"新增表达方式"}),e.jsx(at,{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(ne,{id:"situation",value:d.situation,onChange:N=>m({...d,situation:N.target.value}),placeholder:"描述使用场景"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T,{htmlFor:"style",children:["风格 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(ne,{id:"style",value:d.style,onChange:N=>m({...d,style:N.target.value}),placeholder:"描述表达风格"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T,{htmlFor:"chat_id",children:["聊天 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(Pe,{value:d.chat_id,onValueChange:N=>m({...d,chat_id:N}),children:[e.jsx(Be,{children:e.jsx(Fe,{placeholder:"选择关联的聊天"})}),e.jsx(Ie,{children:r.map(N=>e.jsx(W,{value:N.chat_id,children:e.jsxs("span",{className:"truncate",style:{wordBreak:"keep-all"},children:[N.chat_name,N.is_group&&e.jsx("span",{className:"text-muted-foreground ml-1",children:"(群聊)"})]})},N.chat_id))})]})]})]}),e.jsxs(gt,{children:[e.jsx(_,{variant:"outline",onClick:()=>l(!1),children:"取消"}),e.jsx(_,{onClick:g,disabled:h,children:h?"创建中...":"创建"})]})]})})}function mk({expression:a,open:l,onOpenChange:r,chatList:c,onSuccess:d}){const[m,h]=u.useState({}),[f,p]=u.useState(!1),{toast:g}=nt();u.useEffect(()=>{a&&h({situation:a.situation,style:a.style,chat_id:a.chat_id,checked:a.checked,rejected:a.rejected})},[a]);const N=async()=>{if(a)try{p(!0),await r2(a.id,m),g({title:"保存成功",description:"表达方式已更新"}),d()}catch(j){g({title:"保存失败",description:j instanceof Error?j.message:"无法更新表达方式",variant:"destructive"})}finally{p(!1)}};return a?e.jsx(Qs,{open:l,onOpenChange:r,children:e.jsxs(Hs,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(qs,{children:[e.jsx(Vs,{children:"编辑表达方式"}),e.jsx(at,{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(ne,{id:"edit_situation",value:m.situation||"",onChange:j=>h({...m,situation:j.target.value}),placeholder:"描述使用场景"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"edit_style",children:"风格"}),e.jsx(ne,{id:"edit_style",value:m.style||"",onChange:j=>h({...m,style:j.target.value}),placeholder:"描述表达风格"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"edit_chat_id",children:"聊天"}),e.jsxs(Pe,{value:m.chat_id||"",onValueChange:j=>h({...m,chat_id:j}),children:[e.jsx(Be,{children:e.jsx(Fe,{placeholder:"选择关联的聊天"})}),e.jsx(Ie,{children:c.map(j=>e.jsx(W,{value:j.chat_id,children:e.jsxs("span",{className:"truncate",style:{wordBreak:"keep-all"},children:[j.chat_name,j.is_group&&e.jsx("span",{className:"text-muted-foreground ml-1",children:"(群聊)"})]})},j.chat_id))})]})]}),e.jsxs(ht,{children:[e.jsx(Yt,{className:"h-4 w-4"}),e.jsx(ft,{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:m.checked??!1,onCheckedChange:j=>h({...m,checked:j})})]}),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:m.rejected??!1,onCheckedChange:j=>h({...m,rejected:j})})]})]})]}),e.jsxs(gt,{children:[e.jsx(_,{variant:"outline",onClick:()=>r(!1),children:"取消"}),e.jsx(_,{onClick:N,disabled:f,children:f?"保存中...":"保存"})]})]})}):null}function xk({open:a,onOpenChange:l,onConfirm:r,count:c}){return e.jsx(bs,{open:a,onOpenChange:l,children:e.jsxs(xs,{children:[e.jsxs(hs,{children:[e.jsx(ps,{children:"确认批量删除"}),e.jsxs(gs,{children:["您即将删除 ",c," 个表达方式,此操作无法撤销。确定要继续吗?"]})]}),e.jsxs(fs,{children:[e.jsx(vs,{children:"取消"}),e.jsx(js,{onClick:r,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"确认删除"})]})]})})}const Kl="/api/webui/jargon";async function hk(){const a=await ke(`${Kl}/chats`,{});if(!a.ok){const l=await a.json();throw new Error(l.detail||"获取聊天列表失败")}return a.json()}async function fk(a){const l=new URLSearchParams;a.page&&l.append("page",a.page.toString()),a.page_size&&l.append("page_size",a.page_size.toString()),a.search&&l.append("search",a.search),a.chat_id&&l.append("chat_id",a.chat_id),a.is_jargon!==void 0&&a.is_jargon!==null&&l.append("is_jargon",a.is_jargon.toString()),a.is_global!==void 0&&l.append("is_global",a.is_global.toString());const r=await ke(`${Kl}/list?${l}`,{});if(!r.ok){const c=await r.json();throw new Error(c.detail||"获取黑话列表失败")}return r.json()}async function pk(a){const l=await ke(`${Kl}/${a}`,{});if(!l.ok){const r=await l.json();throw new Error(r.detail||"获取黑话详情失败")}return l.json()}async function gk(a){const l=await ke(`${Kl}/`,{method:"POST",body:JSON.stringify(a)});if(!l.ok){const r=await l.json();throw new Error(r.detail||"创建黑话失败")}return l.json()}async function jk(a,l){const r=await ke(`${Kl}/${a}`,{method:"PATCH",body:JSON.stringify(l)});if(!r.ok){const c=await r.json();throw new Error(c.detail||"更新黑话失败")}return r.json()}async function vk(a){const l=await ke(`${Kl}/${a}`,{method:"DELETE"});if(!l.ok){const r=await l.json();throw new Error(r.detail||"删除黑话失败")}return l.json()}async function Nk(a){const l=await ke(`${Kl}/batch/delete`,{method:"POST",body:JSON.stringify({ids:a})});if(!l.ok){const r=await l.json();throw new Error(r.detail||"批量删除黑话失败")}return l.json()}async function bk(){const a=await ke(`${Kl}/stats/summary`,{});if(!a.ok){const l=await a.json();throw new Error(l.detail||"获取黑话统计失败")}return a.json()}async function yk(a,l){const r=new URLSearchParams;a.forEach(d=>r.append("ids",d.toString())),r.append("is_jargon",l.toString());const c=await ke(`${Kl}/batch/set-jargon?${r}`,{method:"POST"});if(!c.ok){const d=await c.json();throw new Error(d.detail||"批量设置黑话状态失败")}return c.json()}function wk(){const[a,l]=u.useState([]),[r,c]=u.useState(!0),[d,m]=u.useState(0),[h,f]=u.useState(1),[p,g]=u.useState(20),[N,j]=u.useState(""),[b,y]=u.useState("all"),[w,z]=u.useState("all"),[M,S]=u.useState(null),[F,E]=u.useState(!1),[C,R]=u.useState(!1),[H,O]=u.useState(!1),[X,L]=u.useState(null),[me,Ne]=u.useState(new Set),[je,ce]=u.useState(!1),[ge,pe]=u.useState(""),[D,Q]=u.useState({total:0,confirmed_jargon:0,confirmed_not_jargon:0,pending:0,global_count:0,complete_count:0,chat_count:0,top_chats:{}}),[B,ue]=u.useState([]),{toast:Y}=nt(),we=async()=>{try{c(!0);const Z=await fk({page:h,page_size:p,search:N||void 0,chat_id:b==="all"?void 0:b,is_jargon:w==="all"?void 0:w==="true"?!0:w==="false"?!1:void 0});l(Z.data),m(Z.total)}catch(Z){Y({title:"加载失败",description:Z instanceof Error?Z.message:"无法加载黑话列表",variant:"destructive"})}finally{c(!1)}},fe=async()=>{try{const Z=await bk();Z?.data&&Q(Z.data)}catch(Z){console.error("加载统计数据失败:",Z)}},Ee=async()=>{try{const Z=await hk();Z?.data&&ue(Z.data)}catch(Z){console.error("加载聊天列表失败:",Z)}};u.useEffect(()=>{we(),fe(),Ee()},[h,p,N,b,w]);const G=async Z=>{try{const Le=await pk(Z.id);S(Le.data),E(!0)}catch(Le){Y({title:"加载详情失败",description:Le instanceof Error?Le.message:"无法加载黑话详情",variant:"destructive"})}},$=Z=>{S(Z),R(!0)},A=async Z=>{try{await vk(Z.id),Y({title:"删除成功",description:`已删除黑话: ${Z.content}`}),L(null),we(),fe()}catch(Le){Y({title:"删除失败",description:Le instanceof Error?Le.message:"无法删除黑话",variant:"destructive"})}},K=Z=>{const Le=new Set(me);Le.has(Z)?Le.delete(Z):Le.add(Z),Ne(Le)},Re=()=>{me.size===a.length&&a.length>0?Ne(new Set):Ne(new Set(a.map(Z=>Z.id)))},se=async()=>{try{await Nk(Array.from(me)),Y({title:"批量删除成功",description:`已删除 ${me.size} 个黑话`}),Ne(new Set),ce(!1),we(),fe()}catch(Z){Y({title:"批量删除失败",description:Z instanceof Error?Z.message:"无法批量删除黑话",variant:"destructive"})}},$e=async Z=>{try{await yk(Array.from(me),Z),Y({title:"操作成功",description:`已将 ${me.size} 个词条设为${Z?"黑话":"非黑话"}`}),Ne(new Set),we(),fe()}catch(Le){Y({title:"操作失败",description:Le instanceof Error?Le.message:"批量设置失败",variant:"destructive"})}},cs=()=>{const Z=parseInt(ge),Le=Math.ceil(d/p);Z>=1&&Z<=Le?(f(Z),pe("")):Y({title:"无效的页码",description:`请输入1-${Le}之间的页码`,variant:"destructive"})},J=Z=>Z===!0?e.jsxs(Ce,{variant:"default",className:"bg-green-600 hover:bg-green-700",children:[e.jsx(Ot,{className:"h-3 w-3 mr-1"}),"是黑话"]}):Z===!1?e.jsxs(Ce,{variant:"secondary",children:[e.jsx(Sa,{className:"h-3 w-3 mr-1"}),"非黑话"]}):e.jsxs(Ce,{variant:"outline",children:[e.jsx(ox,{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(P1,{className:"h-8 w-8",strokeWidth:2}),"黑话管理"]}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm sm:text-base",children:"管理麦麦学习到的黑话和俚语"})]}),e.jsxs(_,{onClick:()=>O(!0),className:"gap-2",children:[e.jsx(Xs,{className:"h-4 w-4"}),"新增黑话"]})]})}),e.jsx(ts,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 pr-4",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 lg:grid-cols-7 gap-3",children:[e.jsxs("div",{className:"rounded-lg border bg-card p-3 sm:p-4",children:[e.jsx("div",{className:"text-xs sm:text-sm text-muted-foreground",children:"总数量"}),e.jsx("div",{className:"text-xl sm:text-2xl font-bold mt-1",children:D.total})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-3 sm:p-4",children:[e.jsx("div",{className:"text-xs sm:text-sm text-muted-foreground",children:"已确认黑话"}),e.jsx("div",{className:"text-xl sm:text-2xl font-bold mt-1 text-green-600",children:D.confirmed_jargon})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-3 sm:p-4",children:[e.jsx("div",{className:"text-xs sm:text-sm text-muted-foreground",children:"确认非黑话"}),e.jsx("div",{className:"text-xl sm:text-2xl font-bold mt-1 text-gray-500",children:D.confirmed_not_jargon})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-3 sm:p-4",children:[e.jsx("div",{className:"text-xs sm:text-sm text-muted-foreground",children:"待判定"}),e.jsx("div",{className:"text-xl sm:text-2xl font-bold mt-1 text-yellow-600",children:D.pending})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-3 sm:p-4",children:[e.jsx("div",{className:"text-xs sm:text-sm text-muted-foreground",children:"全局黑话"}),e.jsx("div",{className:"text-xl sm:text-2xl font-bold mt-1 text-blue-600",children:D.global_count})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-3 sm:p-4",children:[e.jsx("div",{className:"text-xs sm:text-sm text-muted-foreground",children:"推断完成"}),e.jsx("div",{className:"text-xl sm:text-2xl font-bold mt-1 text-purple-600",children:D.complete_count})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-3 sm:p-4",children:[e.jsx("div",{className:"text-xs sm:text-sm text-muted-foreground",children:"关联聊天数"}),e.jsx("div",{className:"text-xl sm:text-2xl font-bold mt-1",children:D.chat_count})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(T,{htmlFor:"search",children:"搜索"}),e.jsxs("div",{className:"relative",children:[e.jsx($t,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(ne,{id:"search",placeholder:"搜索内容、含义...",value:N,onChange:Z=>j(Z.target.value),className:"pl-9"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(T,{children:"聊天筛选"}),e.jsxs(Pe,{value:b,onValueChange:y,children:[e.jsx(Be,{children:e.jsx(Fe,{placeholder:"全部聊天"})}),e.jsxs(Ie,{children:[e.jsx(W,{value:"all",children:"全部聊天"}),B.map(Z=>e.jsx(W,{value:Z.chat_id,children:Z.chat_name},Z.chat_id))]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(T,{children:"状态筛选"}),e.jsxs(Pe,{value:w,onValueChange:z,children:[e.jsx(Be,{children:e.jsx(Fe,{placeholder:"全部状态"})}),e.jsxs(Ie,{children:[e.jsx(W,{value:"all",children:"全部状态"}),e.jsx(W,{value:"true",children:"是黑话"}),e.jsx(W,{value:"false",children:"非黑话"})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(T,{htmlFor:"page-size",children:"每页显示"}),e.jsxs(Pe,{value:p.toString(),onValueChange:Z=>{g(parseInt(Z)),f(1),Ne(new Set)},children:[e.jsx(Be,{id:"page-size",children:e.jsx(Fe,{})}),e.jsxs(Ie,{children:[e.jsx(W,{value:"10",children:"10"}),e.jsx(W,{value:"20",children:"20"}),e.jsx(W,{value:"50",children:"50"}),e.jsx(W,{value:"100",children:"100"})]})]})]})]}),me.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:["已选择 ",me.size," 个"]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>$e(!0),children:[e.jsx(Ot,{className:"h-4 w-4 mr-1"}),"标记为黑话"]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>$e(!1),children:[e.jsx(Sa,{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:()=>ce(!0),children:[e.jsx(os,{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(ql,{children:[e.jsx(Vl,{children:e.jsxs(_t,{children:[e.jsx(ns,{className:"w-12",children:e.jsx(tt,{checked:me.size===a.length&&a.length>0,onCheckedChange:Re})}),e.jsx(ns,{children:"内容"}),e.jsx(ns,{children:"含义"}),e.jsx(ns,{children:"聊天"}),e.jsx(ns,{children:"状态"}),e.jsx(ns,{className:"text-center",children:"次数"}),e.jsx(ns,{className:"text-right",children:"操作"})]})}),e.jsx(Gl,{children:r?e.jsx(_t,{children:e.jsx(Ze,{colSpan:7,className:"text-center py-8 text-muted-foreground",children:"加载中..."})}):a.length===0?e.jsx(_t,{children:e.jsx(Ze,{colSpan:7,className:"text-center py-8 text-muted-foreground",children:"暂无数据"})}):a.map(Z=>e.jsxs(_t,{children:[e.jsx(Ze,{children:e.jsx(tt,{checked:me.has(Z.id),onCheckedChange:()=>K(Z.id)})}),e.jsx(Ze,{className:"font-medium max-w-[200px]",children:e.jsxs("div",{className:"flex items-center gap-2",children:[Z.is_global&&e.jsx("span",{title:"全局黑话",children:e.jsx(Go,{className:"h-4 w-4 text-blue-500 flex-shrink-0"})}),e.jsx("span",{className:"truncate",title:Z.content,children:Z.content})]})}),e.jsx(Ze,{className:"max-w-[200px] truncate",title:Z.meaning||"",children:Z.meaning||e.jsx("span",{className:"text-muted-foreground",children:"-"})}),e.jsx(Ze,{className:"max-w-[150px] truncate",title:Z.chat_name||Z.chat_id,children:Z.chat_name||Z.chat_id}),e.jsx(Ze,{children:J(Z.is_jargon)}),e.jsx(Ze,{className:"text-center",children:Z.count}),e.jsx(Ze,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(_,{variant:"default",size:"sm",onClick:()=>$(Z),children:[e.jsx(sr,{className:"h-4 w-4 mr-1"}),"编辑"]}),e.jsx(_,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>G(Z),title:"查看详情",children:e.jsx(ua,{className:"h-4 w-4"})}),e.jsxs(_,{size:"sm",onClick:()=>L(Z),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(os,{className:"h-4 w-4 mr-1"}),"删除"]})]})})]},Z.id))})]})}),e.jsx("div",{className:"md:hidden space-y-3 p-4",children:r?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):a.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无数据"}):a.map(Z=>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(tt,{checked:me.has(Z.id),onCheckedChange:()=>K(Z.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:[Z.is_global&&e.jsx(Go,{className:"h-4 w-4 text-blue-500 flex-shrink-0"}),e.jsx("h3",{className:"font-semibold text-sm break-all",children:Z.content})]}),Z.meaning&&e.jsx("p",{className:"text-sm text-muted-foreground break-all",children:Z.meaning}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs",children:[J(Z.is_jargon),e.jsxs("span",{className:"text-muted-foreground",children:["次数: ",Z.count]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground truncate",children:["聊天: ",Z.chat_name||Z.chat_id]})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-1 pt-2 border-t",children:[e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>$(Z),className:"text-xs px-2 py-1 h-auto",children:[e.jsx(sr,{className:"h-3 w-3 mr-1"}),"编辑"]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>G(Z),className:"text-xs px-2 py-1 h-auto",children:e.jsx(ua,{className:"h-3 w-3"})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>L(Z),className:"text-xs px-2 py-1 h-auto text-destructive hover:text-destructive",children:[e.jsx(os,{className:"h-3 w-3 mr-1"}),"删除"]})]})]},Z.id))}),d>0&&e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4 px-4 py-3 border-t",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["共 ",d," 条记录,第 ",h," / ",Math.ceil(d/p)," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>f(1),disabled:h===1,className:"hidden sm:flex",children:e.jsx(kn,{className:"h-4 w-4"})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>f(h-1),disabled:h===1,children:[e.jsx(Pa,{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(ne,{type:"number",value:ge,onChange:Z=>pe(Z.target.value),onKeyDown:Z=>Z.key==="Enter"&&cs(),placeholder:h.toString(),className:"w-16 h-8 text-center",min:1,max:Math.ceil(d/p)}),e.jsx(_,{variant:"outline",size:"sm",onClick:cs,disabled:!ge,className:"h-8",children:"跳转"})]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>f(h+1),disabled:h>=Math.ceil(d/p),children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(ra,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>f(Math.ceil(d/p)),disabled:h>=Math.ceil(d/p),className:"hidden sm:flex",children:e.jsx(Cn,{className:"h-4 w-4"})})]})]})]})]})}),e.jsx(_k,{jargon:M,open:F,onOpenChange:E}),e.jsx(Sk,{open:H,onOpenChange:O,chatList:B,onSuccess:()=>{we(),fe(),O(!1)}}),e.jsx(kk,{jargon:M,open:C,onOpenChange:R,chatList:B,onSuccess:()=>{we(),fe(),R(!1)}}),e.jsx(bs,{open:!!X,onOpenChange:()=>L(null),children:e.jsxs(xs,{children:[e.jsxs(hs,{children:[e.jsx(ps,{children:"确认删除"}),e.jsxs(gs,{children:['确定要删除黑话 "',X?.content,'" 吗?此操作不可撤销。']})]}),e.jsxs(fs,{children:[e.jsx(vs,{children:"取消"}),e.jsx(js,{onClick:()=>X&&A(X),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"删除"})]})]})}),e.jsx(bs,{open:je,onOpenChange:ce,children:e.jsxs(xs,{children:[e.jsxs(hs,{children:[e.jsx(ps,{children:"确认批量删除"}),e.jsxs(gs,{children:["您即将删除 ",me.size," 个黑话,此操作无法撤销。确定要继续吗?"]})]}),e.jsxs(fs,{children:[e.jsx(vs,{children:"取消"}),e.jsx(js,{onClick:se,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"确认删除"})]})]})})]})}function _k({jargon:a,open:l,onOpenChange:r}){return a?e.jsx(Qs,{open:l,onOpenChange:r,children:e.jsxs(Hs,{className:"max-w-2xl max-h-[80vh] grid grid-rows-[auto_1fr_auto] overflow-hidden",children:[e.jsxs(qs,{children:[e.jsx(Vs,{children:"黑话详情"}),e.jsx(at,{children:"查看黑话的完整信息"})]}),e.jsx(ts,{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(Gm,{icon:Wr,label:"记录ID",value:a.id.toString(),mono:!0}),e.jsx(Gm,{label:"使用次数",value:a.count.toString()})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:"内容"}),e.jsx("div",{className:"text-sm p-2 bg-muted rounded break-all whitespace-pre-wrap",children:a.content})]}),a.raw_content&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:"原始内容"}),e.jsx("div",{className:"text-sm p-2 bg-muted rounded break-all",children:(()=>{try{const c=JSON.parse(a.raw_content);return Array.isArray(c)?c.map((d,m)=>e.jsxs("div",{children:[m>0&&e.jsx("hr",{className:"my-3 border-border"}),e.jsx("div",{className:"whitespace-pre-wrap",children:d})]},m)):e.jsx("div",{className:"whitespace-pre-wrap",children:a.raw_content})}catch{return e.jsx("div",{className:"whitespace-pre-wrap",children:a.raw_content})}})()})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:"含义"}),e.jsx("div",{className:"text-sm p-2 bg-muted rounded break-all",children:a.meaning?e.jsx(bx,{content:a.meaning}):"-"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(Gm,{label:"聊天",value:a.chat_name||a.chat_id}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:"状态"}),e.jsxs("div",{className:"flex items-center gap-2",children:[a.is_jargon===!0&&e.jsx(Ce,{variant:"default",className:"bg-green-600",children:"是黑话"}),a.is_jargon===!1&&e.jsx(Ce,{variant:"secondary",children:"非黑话"}),a.is_jargon===null&&e.jsx(Ce,{variant:"outline",children:"未判定"}),a.is_global&&e.jsx(Ce,{variant:"outline",className:"border-blue-500 text-blue-500",children:"全局"}),a.is_complete&&e.jsx(Ce,{variant:"outline",className:"border-purple-500 text-purple-500",children:"推断完成"})]})]})]}),a.inference_with_context&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:"上下文推断结果"}),e.jsx("div",{className:"p-2 bg-muted rounded break-all whitespace-pre-wrap font-mono text-xs max-h-[200px] overflow-y-auto",children:a.inference_with_context})]}),a.inference_content_only&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:"纯词条推断结果"}),e.jsx("div",{className:"p-2 bg-muted rounded break-all whitespace-pre-wrap font-mono text-xs max-h-[200px] overflow-y-auto",children:a.inference_content_only})]})]})}),e.jsx(gt,{className:"flex-shrink-0",children:e.jsx(_,{onClick:()=>r(!1),children:"关闭"})})]})}):null}function Gm({icon:a,label:l,value:r,mono:c=!1}){return e.jsxs("div",{className:"space-y-1",children:[e.jsxs(T,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[a&&e.jsx(a,{className:"h-3 w-3"}),l]}),e.jsx("div",{className:P("text-sm",c&&"font-mono",!r&&"text-muted-foreground"),children:r||"-"})]})}function Sk({open:a,onOpenChange:l,chatList:r,onSuccess:c}){const[d,m]=u.useState({content:"",meaning:"",chat_id:"",is_global:!1}),[h,f]=u.useState(!1),{toast:p}=nt(),g=async()=>{if(!d.content||!d.chat_id){p({title:"验证失败",description:"请填写必填字段:内容和聊天",variant:"destructive"});return}try{f(!0),await gk(d),p({title:"创建成功",description:"黑话已创建"}),m({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(Qs,{open:a,onOpenChange:l,children:e.jsxs(Hs,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(qs,{children:[e.jsx(Vs,{children:"新增黑话"}),e.jsx(at,{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(ne,{id:"content",value:d.content,onChange:N=>m({...d,content:N.target.value}),placeholder:"输入黑话内容"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"meaning",children:"含义"}),e.jsx(pt,{id:"meaning",value:d.meaning||"",onChange:N=>m({...d,meaning:N.target.value}),placeholder:"输入黑话含义(可选)",rows:3})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T,{htmlFor:"chat_id",children:["聊天 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(Pe,{value:d.chat_id,onValueChange:N=>m({...d,chat_id:N}),children:[e.jsx(Be,{children:e.jsx(Fe,{placeholder:"选择关联的聊天"})}),e.jsx(Ie,{children:r.map(N=>e.jsx(W,{value:N.chat_id,children:N.chat_name},N.chat_id))})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ge,{id:"is_global",checked:d.is_global,onCheckedChange:N=>m({...d,is_global:N})}),e.jsx(T,{htmlFor:"is_global",children:"设为全局黑话"})]})]}),e.jsxs(gt,{children:[e.jsx(_,{variant:"outline",onClick:()=>l(!1),children:"取消"}),e.jsx(_,{onClick:g,disabled:h,children:h?"创建中...":"创建"})]})]})})}function kk({jargon:a,open:l,onOpenChange:r,chatList:c,onSuccess:d}){const[m,h]=u.useState({}),[f,p]=u.useState(!1),{toast:g}=nt();u.useEffect(()=>{a&&h({content:a.content,meaning:a.meaning||"",chat_id:a.stream_id||a.chat_id,is_global:a.is_global,is_jargon:a.is_jargon})},[a]);const N=async()=>{if(a)try{p(!0),await jk(a.id,m),g({title:"保存成功",description:"黑话已更新"}),d()}catch(j){g({title:"保存失败",description:j instanceof Error?j.message:"无法更新黑话",variant:"destructive"})}finally{p(!1)}};return a?e.jsx(Qs,{open:l,onOpenChange:r,children:e.jsxs(Hs,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(qs,{children:[e.jsx(Vs,{children:"编辑黑话"}),e.jsx(at,{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(ne,{id:"edit_content",value:m.content||"",onChange:j=>h({...m,content:j.target.value}),placeholder:"输入黑话内容"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"edit_meaning",children:"含义"}),e.jsx(pt,{id:"edit_meaning",value:m.meaning||"",onChange:j=>h({...m,meaning:j.target.value}),placeholder:"输入黑话含义",rows:3})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"edit_chat_id",children:"聊天"}),e.jsxs(Pe,{value:m.chat_id||"",onValueChange:j=>h({...m,chat_id:j}),children:[e.jsx(Be,{children:e.jsx(Fe,{placeholder:"选择关联的聊天"})}),e.jsx(Ie,{children:c.map(j=>e.jsx(W,{value:j.chat_id,children:j.chat_name},j.chat_id))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"黑话状态"}),e.jsxs(Pe,{value:m.is_jargon===null?"null":m.is_jargon?.toString()||"null",onValueChange:j=>h({...m,is_jargon:j==="null"?null:j==="true"}),children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsxs(Ie,{children:[e.jsx(W,{value:"null",children:"未判定"}),e.jsx(W,{value:"true",children:"是黑话"}),e.jsx(W,{value:"false",children:"非黑话"})]})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ge,{id:"edit_is_global",checked:m.is_global,onCheckedChange:j=>h({...m,is_global:j})}),e.jsx(T,{htmlFor:"edit_is_global",children:"全局黑话"})]})]}),e.jsxs(gt,{children:[e.jsx(_,{variant:"outline",onClick:()=>r(!1),children:"取消"}),e.jsx(_,{onClick:N,disabled:f,children:f?"保存中...":"保存"})]})]})}):null}const li="/api/webui/person";async function Ck(a){const l=new URLSearchParams;a.page&&l.append("page",a.page.toString()),a.page_size&&l.append("page_size",a.page_size.toString()),a.search&&l.append("search",a.search),a.is_known!==void 0&&l.append("is_known",a.is_known.toString()),a.platform&&l.append("platform",a.platform);const r=await ke(`${li}/list?${l}`,{headers:Zs()});if(!r.ok){const c=await r.json();throw new Error(c.detail||"获取人物列表失败")}return r.json()}async function Tk(a){const l=await ke(`${li}/${a}`,{headers:Zs()});if(!l.ok){const r=await l.json();throw new Error(r.detail||"获取人物详情失败")}return l.json()}async function Ek(a,l){const r=await ke(`${li}/${a}`,{method:"PATCH",headers:Zs(),body:JSON.stringify(l)});if(!r.ok){const c=await r.json();throw new Error(c.detail||"更新人物信息失败")}return r.json()}async function Mk(a){const l=await ke(`${li}/${a}`,{method:"DELETE",headers:Zs()});if(!l.ok){const r=await l.json();throw new Error(r.detail||"删除人物信息失败")}return l.json()}async function Ak(){const a=await ke(`${li}/stats/summary`,{headers:Zs()});if(!a.ok){const l=await a.json();throw new Error(l.detail||"获取统计数据失败")}return a.json()}async function zk(a){const l=await ke(`${li}/batch/delete`,{method:"POST",headers:Zs(),body:JSON.stringify({person_ids:a})});if(!l.ok){const r=await l.json();throw new Error(r.detail||"批量删除失败")}return l.json()}function Rk(){const[a,l]=u.useState([]),[r,c]=u.useState(!0),[d,m]=u.useState(0),[h,f]=u.useState(1),[p,g]=u.useState(20),[N,j]=u.useState(""),[b,y]=u.useState(void 0),[w,z]=u.useState(void 0),[M,S]=u.useState(null),[F,E]=u.useState(!1),[C,R]=u.useState(!1),[H,O]=u.useState(null),[X,L]=u.useState({total:0,known:0,unknown:0,platforms:{}}),[me,Ne]=u.useState(new Set),[je,ce]=u.useState(!1),[ge,pe]=u.useState(""),{toast:D}=nt(),Q=async()=>{try{c(!0);const se=await Ck({page:h,page_size:p,search:N||void 0,is_known:b,platform:w});l(se.data),m(se.total)}catch(se){D({title:"加载失败",description:se instanceof Error?se.message:"无法加载人物信息",variant:"destructive"})}finally{c(!1)}},B=async()=>{try{const se=await Ak();se?.data&&L(se.data)}catch(se){console.error("加载统计数据失败:",se)}};u.useEffect(()=>{Q(),B()},[h,p,N,b,w]);const ue=async se=>{try{const $e=await Tk(se.person_id);S($e.data),E(!0)}catch($e){D({title:"加载详情失败",description:$e instanceof Error?$e.message:"无法加载人物详情",variant:"destructive"})}},Y=se=>{S(se),R(!0)},we=async se=>{try{await Mk(se.person_id),D({title:"删除成功",description:`已删除人物信息: ${se.person_name||se.nickname||se.user_id}`}),O(null),Q(),B()}catch($e){D({title:"删除失败",description:$e instanceof Error?$e.message:"无法删除人物信息",variant:"destructive"})}},fe=u.useMemo(()=>Object.keys(X.platforms),[X.platforms]),Ee=se=>{const $e=new Set(me);$e.has(se)?$e.delete(se):$e.add(se),Ne($e)},G=()=>{me.size===a.length&&a.length>0?Ne(new Set):Ne(new Set(a.map(se=>se.person_id)))},$=()=>{if(me.size===0){D({title:"未选择任何人物",description:"请先选择要删除的人物",variant:"destructive"});return}ce(!0)},A=async()=>{try{const se=await zk(Array.from(me));D({title:"批量删除完成",description:se.message}),Ne(new Set),ce(!1),Q(),B()}catch(se){D({title:"批量删除失败",description:se instanceof Error?se.message:"批量删除失败",variant:"destructive"})}},K=()=>{const se=parseInt(ge),$e=Math.ceil(d/p);se>=1&&se<=$e?(f(se),pe("")):D({title:"无效的页码",description:`请输入1-${$e}之间的页码`,variant:"destructive"})},Re=se=>se?new Date(se*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(oc,{className:"h-8 w-8",strokeWidth:2}),"人物信息管理"]}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm sm:text-base",children:"管理麦麦认识的所有人物信息"})]})})}),e.jsx(ts,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 pr-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"总人数"}),e.jsx("div",{className:"text-2xl font-bold mt-1",children:X.total})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"已认识"}),e.jsx("div",{className:"text-2xl font-bold mt-1 text-green-600",children:X.known})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"未认识"}),e.jsx("div",{className:"text-2xl font-bold mt-1 text-muted-foreground",children:X.unknown})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx(T,{htmlFor:"search",children:"搜索"}),e.jsxs("div",{className:"relative mt-1.5",children:[e.jsx($t,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(ne,{id:"search",placeholder:"搜索名称、昵称或用户ID...",value:N,onChange:se=>j(se.target.value),className:"pl-9"})]})]}),e.jsxs("div",{children:[e.jsx(T,{htmlFor:"filter-known",children:"认识状态"}),e.jsxs(Pe,{value:b===void 0?"all":b.toString(),onValueChange:se=>{y(se==="all"?void 0:se==="true"),f(1)},children:[e.jsx(Be,{id:"filter-known",className:"mt-1.5",children:e.jsx(Fe,{})}),e.jsxs(Ie,{children:[e.jsx(W,{value:"all",children:"全部"}),e.jsx(W,{value:"true",children:"已认识"}),e.jsx(W,{value:"false",children:"未认识"})]})]})]}),e.jsxs("div",{children:[e.jsx(T,{htmlFor:"filter-platform",children:"平台"}),e.jsxs(Pe,{value:w||"all",onValueChange:se=>{z(se==="all"?void 0:se),f(1)},children:[e.jsx(Be,{id:"filter-platform",className:"mt-1.5",children:e.jsx(Fe,{})}),e.jsxs(Ie,{children:[e.jsx(W,{value:"all",children:"全部平台"}),fe.map(se=>e.jsxs(W,{value:se,children:[se," (",X.platforms[se],")"]},se))]})]})]})]}),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:me.size>0&&e.jsxs("span",{children:["已选择 ",me.size," 个人物"]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{htmlFor:"page-size",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(Pe,{value:p.toString(),onValueChange:se=>{g(parseInt(se)),f(1),Ne(new Set)},children:[e.jsx(Be,{id:"page-size",className:"w-20",children:e.jsx(Fe,{})}),e.jsxs(Ie,{children:[e.jsx(W,{value:"10",children:"10"}),e.jsx(W,{value:"20",children:"20"}),e.jsx(W,{value:"50",children:"50"}),e.jsx(W,{value:"100",children:"100"})]})]}),me.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:$,children:[e.jsx(os,{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(ql,{children:[e.jsx(Vl,{children:e.jsxs(_t,{children:[e.jsx(ns,{className:"w-12",children:e.jsx(tt,{checked:a.length>0&&me.size===a.length,onCheckedChange:G,"aria-label":"全选"})}),e.jsx(ns,{children:"状态"}),e.jsx(ns,{children:"名称"}),e.jsx(ns,{children:"昵称"}),e.jsx(ns,{children:"平台"}),e.jsx(ns,{children:"用户ID"}),e.jsx(ns,{children:"最后更新"}),e.jsx(ns,{className:"text-right",children:"操作"})]})}),e.jsx(Gl,{children:r?e.jsx(_t,{children:e.jsx(Ze,{colSpan:8,className:"text-center py-8 text-muted-foreground",children:"加载中..."})}):a.length===0?e.jsx(_t,{children:e.jsx(Ze,{colSpan:8,className:"text-center py-8 text-muted-foreground",children:"暂无数据"})}):a.map(se=>e.jsxs(_t,{children:[e.jsx(Ze,{children:e.jsx(tt,{checked:me.has(se.person_id),onCheckedChange:()=>Ee(se.person_id),"aria-label":`选择 ${se.person_name||se.nickname||se.user_id}`})}),e.jsx(Ze,{children:e.jsx("div",{className:P("inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium",se.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:se.is_known?"已认识":"未认识"})}),e.jsx(Ze,{className:"font-medium",children:se.person_name||e.jsx("span",{className:"text-muted-foreground",children:"-"})}),e.jsx(Ze,{children:se.nickname||"-"}),e.jsx(Ze,{children:se.platform}),e.jsx(Ze,{className:"font-mono text-sm",children:se.user_id}),e.jsx(Ze,{className:"text-sm text-muted-foreground",children:Re(se.last_know)}),e.jsx(Ze,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(_,{variant:"default",size:"sm",onClick:()=>ue(se),children:[e.jsx(ua,{className:"h-4 w-4 mr-1"}),"详情"]}),e.jsxs(_,{variant:"default",size:"sm",onClick:()=>Y(se),children:[e.jsx(sr,{className:"h-4 w-4 mr-1"}),"编辑"]}),e.jsxs(_,{size:"sm",onClick:()=>O(se),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(os,{className:"h-4 w-4 mr-1"}),"删除"]})]})})]},se.id))})]})}),e.jsx("div",{className:"md:hidden space-y-3 p-4",children:r?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):a.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无数据"}):a.map(se=>e.jsxs("div",{className:"rounded-lg border bg-card p-4 space-y-3 overflow-hidden",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(tt,{checked:me.has(se.person_id),onCheckedChange:()=>Ee(se.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",se.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:se.is_known?"已认识":"未认识"}),e.jsx("h3",{className:"font-semibold text-sm line-clamp-1 w-full break-all",children:se.person_name||e.jsx("span",{className:"text-muted-foreground",children:"未命名"})}),se.nickname&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1 line-clamp-1 w-full break-all",children:["昵称: ",se.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:se.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:se.user_id,children:se.user_id})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"最后更新"}),e.jsx("p",{className:"text-xs",children:Re(se.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(se),className:"text-xs px-2 py-1 h-auto flex-shrink-0",children:[e.jsx(ua,{className:"h-3 w-3 mr-1"}),"查看"]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>Y(se),className:"text-xs px-2 py-1 h-auto flex-shrink-0",children:[e.jsx(sr,{className:"h-3 w-3 mr-1"}),"编辑"]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>O(se),className:"text-xs px-2 py-1 h-auto flex-shrink-0 text-destructive hover:text-destructive",children:[e.jsx(os,{className:"h-3 w-3 mr-1"}),"删除"]})]})]},se.id))}),d>0&&e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4 px-4 py-3 border-t",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["共 ",d," 条记录,第 ",h," / ",Math.ceil(d/p)," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>f(1),disabled:h===1,className:"hidden sm:flex",children:e.jsx(kn,{className:"h-4 w-4"})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>f(h-1),disabled:h===1,children:[e.jsx(Pa,{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(ne,{type:"number",value:ge,onChange:se=>pe(se.target.value),onKeyDown:se=>se.key==="Enter"&&K(),placeholder:h.toString(),className:"w-16 h-8 text-center",min:1,max:Math.ceil(d/p)}),e.jsx(_,{variant:"outline",size:"sm",onClick:K,disabled:!ge,className:"h-8",children:"跳转"})]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>f(h+1),disabled:h>=Math.ceil(d/p),children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(ra,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>f(Math.ceil(d/p)),disabled:h>=Math.ceil(d/p),className:"hidden sm:flex",children:e.jsx(Cn,{className:"h-4 w-4"})})]})]})]})]})}),e.jsx(Dk,{person:M,open:F,onOpenChange:E}),e.jsx(Ok,{person:M,open:C,onOpenChange:R,onSuccess:()=>{Q(),B(),R(!1)}}),e.jsx(bs,{open:!!H,onOpenChange:()=>O(null),children:e.jsxs(xs,{children:[e.jsxs(hs,{children:[e.jsx(ps,{children:"确认删除"}),e.jsxs(gs,{children:['确定要删除人物信息 "',H?.person_name||H?.nickname||H?.user_id,'" 吗? 此操作不可撤销。']})]}),e.jsxs(fs,{children:[e.jsx(vs,{children:"取消"}),e.jsx(js,{onClick:()=>H&&we(H),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"删除"})]})]})}),e.jsx(bs,{open:je,onOpenChange:ce,children:e.jsxs(xs,{children:[e.jsxs(hs,{children:[e.jsx(ps,{children:"确认批量删除"}),e.jsxs(gs,{children:["确定要删除选中的 ",me.size," 个人物信息吗? 此操作不可撤销。"]})]}),e.jsxs(fs,{children:[e.jsx(vs,{children:"取消"}),e.jsx(js,{onClick:A,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"批量删除"})]})]})})]})}function Dk({person:a,open:l,onOpenChange:r}){if(!a)return null;const c=d=>d?new Date(d*1e3).toLocaleString("zh-CN"):"-";return e.jsx(Qs,{open:l,onOpenChange:r,children:e.jsxs(Hs,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(qs,{children:[e.jsx(Vs,{children:"人物详情"}),e.jsxs(at,{children:["查看 ",a.person_name||a.nickname||a.user_id," 的完整信息"]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx($l,{icon:Fl,label:"人物名称",value:a.person_name}),e.jsx($l,{icon:Ia,label:"昵称",value:a.nickname}),e.jsx($l,{icon:Wr,label:"用户ID",value:a.user_id,mono:!0}),e.jsx($l,{icon:Wr,label:"人物ID",value:a.person_id,mono:!0}),e.jsx($l,{label:"平台",value:a.platform}),e.jsx($l,{label:"状态",value:a.is_known?"已认识":"未认识"})]}),a.name_reason&&e.jsxs("div",{className:"rounded-lg border bg-muted/50 p-3",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:"名称设定原因"}),e.jsx("p",{className:"mt-1 text-sm",children:a.name_reason})]}),a.memory_points&&e.jsxs("div",{className:"rounded-lg border bg-muted/50 p-3",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:"个人印象"}),e.jsx("p",{className:"mt-1 text-sm whitespace-pre-wrap",children:a.memory_points})]}),a.group_nick_name&&a.group_nick_name.length>0&&e.jsxs("div",{className:"rounded-lg border bg-muted/50 p-3",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:"群昵称"}),e.jsx("div",{className:"mt-2 space-y-1",children:a.group_nick_name.map((d,m)=>e.jsxs("div",{className:"text-sm flex items-center gap-2",children:[e.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:d.group_id}),e.jsx("span",{children:"→"}),e.jsx("span",{children:d.group_nick_name})]},m))})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsx($l,{icon:da,label:"认识时间",value:c(a.know_times)}),e.jsx($l,{icon:da,label:"首次记录",value:c(a.know_since)}),e.jsx($l,{icon:da,label:"最后更新",value:c(a.last_know)})]})]}),e.jsx(gt,{children:e.jsx(_,{onClick:()=>r(!1),children:"关闭"})})]})})}function $l({icon:a,label:l,value:r,mono:c=!1}){return e.jsxs("div",{className:"space-y-1",children:[e.jsxs(T,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[a&&e.jsx(a,{className:"h-3 w-3"}),l]}),e.jsx("div",{className:P("text-sm",c&&"font-mono",!r&&"text-muted-foreground"),children:r||"-"})]})}function Ok({person:a,open:l,onOpenChange:r,onSuccess:c}){const[d,m]=u.useState({}),[h,f]=u.useState(!1),{toast:p}=nt();u.useEffect(()=>{a&&m({person_name:a.person_name||"",name_reason:a.name_reason||"",nickname:a.nickname||"",is_known:a.is_known})},[a]);const g=async()=>{if(a)try{f(!0),await Ek(a.person_id,d),p({title:"保存成功",description:"人物信息已更新"}),c()}catch(N){p({title:"保存失败",description:N instanceof Error?N.message:"无法更新人物信息",variant:"destructive"})}finally{f(!1)}};return a?e.jsx(Qs,{open:l,onOpenChange:r,children:e.jsxs(Hs,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(qs,{children:[e.jsx(Vs,{children:"编辑人物信息"}),e.jsxs(at,{children:["修改 ",a.person_name||a.nickname||a.user_id," 的信息"]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"person_name",children:"人物名称"}),e.jsx(ne,{id:"person_name",value:d.person_name||"",onChange:N=>m({...d,person_name:N.target.value}),placeholder:"为这个人设置一个名称"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"nickname",children:"昵称"}),e.jsx(ne,{id:"nickname",value:d.nickname||"",onChange:N=>m({...d,nickname:N.target.value}),placeholder:"昵称"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"name_reason",children:"名称设定原因"}),e.jsx(pt,{id:"name_reason",value:d.name_reason||"",onChange:N=>m({...d,name_reason:N.target.value}),placeholder:"为什么这样称呼这个人?",rows:2})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-3",children:[e.jsxs("div",{children:[e.jsx(T,{htmlFor:"is_known",className:"text-base font-medium",children:"已认识"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"标记是否已经认识这个人"})]}),e.jsx(Ge,{id:"is_known",checked:d.is_known,onCheckedChange:N=>m({...d,is_known:N})})]})]}),e.jsxs(gt,{children:[e.jsx(_,{variant:"outline",onClick:()=>r(!1),children:"取消"}),e.jsx(_,{onClick:g,disabled:h,children:h?"保存中...":"保存"})]})]})}):null}var Lk=S_();const tj=mw(Lk),Mx="/api/webui";async function Uk(a=100,l="all"){const r=`${Mx}/knowledge/graph?limit=${a}&node_type=${l}`,c=await fetch(r);if(!c.ok)throw new Error(`获取知识图谱失败: ${c.status}`);return c.json()}async function $k(){const a=await fetch(`${Mx}/knowledge/stats`);if(!a.ok)throw new Error("获取知识图谱统计信息失败");return a.json()}async function Bk(a){const l=await fetch(`${Mx}/knowledge/search?query=${encodeURIComponent(a)}`);if(!l.ok)throw new Error("搜索知识节点失败");return l.json()}const dN=u.memo(({data:a})=>e.jsxs("div",{className:"px-4 py-2 shadow-md rounded-lg bg-gradient-to-br from-blue-500 to-blue-600 border-2 border-blue-700 min-w-[120px]",children:[e.jsx(Yo,{type:"target",position:Jo.Top}),e.jsx("div",{className:"font-semibold text-white text-sm truncate max-w-[200px]",title:a.content,children:a.label}),e.jsx(Yo,{type:"source",position:Jo.Bottom})]}));dN.displayName="EntityNode";const uN=u.memo(({data:a})=>e.jsxs("div",{className:"px-3 py-2 shadow-md rounded-md bg-gradient-to-br from-green-500 to-green-600 border-2 border-green-700 min-w-[100px]",children:[e.jsx(Yo,{type:"target",position:Jo.Top}),e.jsx("div",{className:"font-medium text-white text-xs truncate max-w-[150px]",title:a.content,children:a.label}),e.jsx(Yo,{type:"source",position:Jo.Bottom})]}));uN.displayName="ParagraphNode";const Ik={entity:dN,paragraph:uN};function Pk(a,l){const r=new tj.graphlib.Graph;r.setDefaultEdgeLabel(()=>({})),r.setGraph({rankdir:"TB",ranksep:100,nodesep:80});const c=[],d=[];return a.forEach(m=>{r.setNode(m.id,{width:150,height:50})}),l.forEach(m=>{r.setEdge(m.source,m.target)}),tj.layout(r),a.forEach(m=>{const h=r.node(m.id);c.push({id:m.id,type:m.type,position:{x:h.x-75,y:h.y-25},data:{label:m.content.slice(0,20)+(m.content.length>20?"...":""),content:m.content}})}),l.forEach((m,h)=>{const f={id:`edge-${h}`,source:m.source,target:m.target,animated:a.length<=200&&m.weight>5,style:{strokeWidth:Math.min(m.weight/2,5),opacity:.6}};m.weight>10&&a.length<100&&(f.label=`${m.weight.toFixed(0)}`),d.push(f)}),{nodes:c,edges:d}}function Fk(){const a=ha(),[l,r]=u.useState(!1),[c,d]=u.useState(null),[m,h]=u.useState(""),[f,p]=u.useState("all"),[g,N]=u.useState(50),[j,b]=u.useState("50"),[y,w]=u.useState(!1),[z,M]=u.useState(!0),[S,F]=u.useState(!1),[E,C]=u.useState(!1),[R,H,O]=k_([]),[X,L,me]=C_([]),[Ne,je]=u.useState(0),[ce,ge]=u.useState(null),[pe,D]=u.useState(null),{toast:Q}=nt(),B=u.useCallback(A=>A.type==="entity"?"#6366f1":A.type==="paragraph"?"#10b981":"#6b7280",[]),ue=u.useCallback(async(A=!1)=>{try{if(!A&&g>200){C(!0);return}r(!0);const[K,Re]=await Promise.all([Uk(g,f),$k()]);if(d(Re),K.nodes.length===0){Q({title:"提示",description:"知识库为空,请先导入知识数据"}),H([]),L([]);return}const{nodes:se,edges:$e}=Pk(K.nodes,K.edges);H(se),L($e),je(se.length),Re&&Re.total_nodes>g&&Q({title:"提示",description:`知识图谱包含 ${Re.total_nodes} 个节点,当前显示 ${se.length} 个`}),Q({title:"加载成功",description:`已加载 ${se.length} 个节点,${$e.length} 条边`})}catch(K){console.error("加载知识图谱失败:",K),Q({title:"加载失败",description:K instanceof Error?K.message:"未知错误",variant:"destructive"})}finally{r(!1)}},[g,f,Q]),Y=u.useCallback(async()=>{if(!m.trim()){Q({title:"提示",description:"请输入搜索关键词"});return}try{const A=await Bk(m);if(A.length===0){Q({title:"未找到",description:"没有找到匹配的节点"});return}const K=new Set(A.map(Re=>Re.id));H(Re=>Re.map(se=>({...se,style:{...se.style,opacity:K.has(se.id)?1:.3,filter:K.has(se.id)?"brightness(1.2)":"brightness(0.8)"}}))),Q({title:"搜索完成",description:`找到 ${A.length} 个匹配节点`})}catch(A){console.error("搜索失败:",A),Q({title:"搜索失败",description:A instanceof Error?A.message:"未知错误",variant:"destructive"})}},[m,Q]),we=u.useCallback(()=>{H(A=>A.map(K=>({...K,style:{...K.style,opacity:1,filter:"brightness(1)"}})))},[]),fe=u.useCallback(()=>{M(!1),F(!0),ue()},[ue]),Ee=u.useCallback(()=>{C(!1),setTimeout(()=>{ue(!0)},0)},[ue]),G=u.useCallback((A,K)=>{R.find(se=>se.id===K.id)&&ge({id:K.id,type:K.type,content:K.data.content})},[R]);u.useEffect(()=>{z||S&&ue()},[g,f,z,S]);const $=u.useCallback((A,K)=>{const Re=R.find(cs=>cs.id===K.source),se=R.find(cs=>cs.id===K.target),$e=X.find(cs=>cs.id===K.id);Re&&se&&$e&&D({source:{id:Re.id,type:Re.type,content:Re.data.content},target:{id:se.id,type:se.type,content:se.data.content},edge:{source:K.source,target:K.target,weight:parseFloat(K.label||"0")}})},[R,X]);return e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{className:"flex-shrink-0 p-4 border-b bg-background",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"麦麦知识库图谱"}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"可视化知识实体与关系网络"})]}),c&&e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsxs(Ce,{variant:"outline",className:"gap-1",children:[e.jsx(Zr,{className:"h-3 w-3"}),"节点: ",c.total_nodes]}),e.jsxs(Ce,{variant:"outline",className:"gap-1",children:[e.jsx(xv,{className:"h-3 w-3"}),"边: ",c.total_edges]}),e.jsxs(Ce,{variant:"outline",className:"gap-1",children:[e.jsx(Yt,{className:"h-3 w-3"}),"实体: ",c.entity_nodes]}),e.jsxs(Ce,{variant:"outline",className:"gap-1",children:[e.jsx(Ua,{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(ne,{placeholder:"搜索节点内容...",value:m,onChange:A=>h(A.target.value),onKeyDown:A=>A.key==="Enter"&&Y(),className:"flex-1"}),e.jsx(_,{onClick:Y,size:"sm",children:e.jsx($t,{className:"h-4 w-4"})}),e.jsx(_,{onClick:we,variant:"outline",size:"sm",children:"重置"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(Pe,{value:f,onValueChange:A=>p(A),children:[e.jsx(Be,{className:"w-[120px]",children:e.jsx(Fe,{})}),e.jsxs(Ie,{children:[e.jsx(W,{value:"all",children:"全部节点"}),e.jsx(W,{value:"entity",children:"仅实体"}),e.jsx(W,{value:"paragraph",children:"仅段落"})]})]}),e.jsxs(Pe,{value:g===1e4?"all":y?"custom":g.toString(),onValueChange:A=>{A==="custom"?(w(!0),b(g.toString())):A==="all"?(w(!1),N(1e4)):(w(!1),N(Number(A)))},children:[e.jsx(Be,{className:"w-[120px]",children:e.jsx(Fe,{})}),e.jsxs(Ie,{children:[e.jsx(W,{value:"50",children:"50 节点"}),e.jsx(W,{value:"100",children:"100 节点"}),e.jsx(W,{value:"200",children:"200 节点"}),e.jsx(W,{value:"500",children:"500 节点"}),e.jsx(W,{value:"1000",children:"1000 节点"}),e.jsx(W,{value:"all",children:"全部 (最多10000)"}),e.jsx(W,{value:"custom",children:"自定义..."})]})]}),y&&e.jsx(ne,{type:"number",min:"50",value:j,onChange:A=>b(A.target.value),onBlur:()=>{const A=parseInt(j);!isNaN(A)&&A>=50?N(A):(b("50"),N(50))},onKeyDown:A=>{if(A.key==="Enter"){const K=parseInt(j);!isNaN(K)&&K>=50?N(K):(b("50"),N(50))}},placeholder:"最少50个",className:"w-[120px]"}),e.jsx(_,{onClick:()=>ue(),variant:"outline",size:"sm",disabled:l,children:e.jsx(dt,{className:P("h-4 w-4",l&&"animate-spin")})})]})]})]}),e.jsx("div",{className:"flex-1 relative",children:l?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:"加载知识图谱中..."})]})}):R.length===0?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(Zr,{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(T_,{nodes:R,edges:X,onNodesChange:O,onEdgesChange:me,onNodeClick:G,onEdgeClick:$,nodeTypes:Ik,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(E_,{variant:M_.Dots,gap:12,size:1}),e.jsx(A_,{}),Ne<=500&&e.jsx(z_,{nodeColor:B,nodeBorderRadius:8,pannable:!0,zoomable:!0}),e.jsxs(R_,{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(Qs,{open:!!ce,onOpenChange:A=>!A&&ge(null),children:e.jsxs(Hs,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsx(qs,{children:e.jsx(Vs,{children:"节点详情"})}),ce&&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(Ce,{variant:ce.type==="entity"?"default":"secondary",children:ce.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:ce.id})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"内容"}),e.jsx(ts,{className:"mt-1 max-h-[400px] p-3 bg-muted rounded border",children:e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:ce.content})})]})]})]})}),e.jsx(Qs,{open:!!pe,onOpenChange:A=>!A&&D(null),children:e.jsxs(Hs,{className:"max-w-2xl max-h-[80vh] overflow-hidden flex flex-col",children:[e.jsx(qs,{children:e.jsx(Vs,{children:"边详情"})}),pe&&e.jsx(ts,{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:pe.source.content}),e.jsxs("code",{className:"text-xs text-muted-foreground truncate block",children:[pe.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:pe.target.content}),e.jsxs("code",{className:"text-xs text-muted-foreground truncate block",children:[pe.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(Ce,{variant:"outline",className:"text-base font-mono",children:pe.edge.weight.toFixed(4)})})]})]})})]})}),e.jsx(bs,{open:z,onOpenChange:M,children:e.jsxs(xs,{children:[e.jsxs(hs,{children:[e.jsx(ps,{children:"加载知识图谱"}),e.jsxs(gs,{children:["知识图谱的动态展示会消耗较多系统资源。",e.jsx("br",{}),"确定要加载知识图谱吗?"]})]}),e.jsxs(fs,{children:[e.jsx(vs,{onClick:()=>a({to:"/"}),children:"取消 (返回首页)"}),e.jsx(js,{onClick:fe,children:"确认加载"})]})]})}),e.jsx(bs,{open:E,onOpenChange:C,children:e.jsxs(xs,{children:[e.jsxs(hs,{children:[e.jsx(ps,{children:"⚠️ 节点数量较多"}),e.jsx(gs,{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(fs,{children:[e.jsx(vs,{onClick:()=>{C(!1),g>200&&(N(50),w(!1))},children:"取消"}),e.jsx(js,{onClick:Ee,className:"bg-orange-600 hover:bg-orange-700",children:"我了解风险,继续加载"})]})]})})]})}function Hk(){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(Te,{children:[e.jsxs(Oe,{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(Zr,{className:"h-10 w-10 text-primary"})}),e.jsx(Ue,{className:"text-2xl",children:"麦麦知识库管理"}),e.jsx(Ns,{className:"text-base",children:"功能开发中,敬请期待"})]}),e.jsx(ze,{className:"text-center text-sm text-muted-foreground",children:e.jsx("p",{children:"此功能将提供知识库的创建、编辑、导入和管理能力"})})]})})})]})}function aj({className:a,classNames:l,showOutsideDays:r=!0,captionLayout:c="label",buttonVariant:d="ghost",formatters:m,components:h,...f}){const p=Ev();return e.jsx(j_,{showOutsideDays:r,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`,a),captionLayout:c,formatters:{formatMonthDropdown:g=>g.toLocaleString("default",{month:"short"}),...m},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(si({variant:d}),"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",p.button_previous),button_next:P(si({variant:d}),"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),...l},components:{Root:({className:g,rootRef:N,...j})=>e.jsx("div",{"data-slot":"calendar",ref:N,className:P(g),...j}),Chevron:({className:g,orientation:N,...j})=>N==="left"?e.jsx(Pa,{className:P("size-4",g),...j}):N==="right"?e.jsx(ra,{className:P("size-4",g),...j}):e.jsx(Ba,{className:P("size-4",g),...j}),DayButton:qk,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 qk({className:a,day:l,modifiers:r,...c}){const d=Ev(),m=u.useRef(null);return u.useEffect(()=>{r.focused&&m.current?.focus()},[r.focused]),e.jsx(_,{ref:m,variant:"ghost",size:"icon","data-day":l.date.toLocaleDateString(),"data-selected-single":r.selected&&!r.range_start&&!r.range_end&&!r.range_middle,"data-range-start":r.range_start,"data-range-end":r.range_end,"data-range-middle":r.range_middle,className: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",d.day,a),...c})}const Uo={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 Vk(){const[a,l]=u.useState([]),[r,c]=u.useState(""),[d,m]=u.useState("all"),[h,f]=u.useState("all"),[p,g]=u.useState(void 0),[N,j]=u.useState(void 0),[b,y]=u.useState(!0),[w,z]=u.useState(!1),[M,S]=u.useState("xs"),[F,E]=u.useState(4),[C,R]=u.useState(!1),H=u.useRef(null);u.useEffect(()=>{const Y=Qn.getAllLogs();l(Y);const we=Qn.onLog(()=>{l(Qn.getAllLogs())}),fe=Qn.onConnectionChange(Ee=>{z(Ee)});return()=>{we(),fe()}},[]);const O=u.useMemo(()=>{const Y=new Set(a.map(we=>we.module).filter(we=>we&&we.trim()!==""));return Array.from(Y).sort()},[a]),X=Y=>{switch(Y){case"DEBUG":return"text-muted-foreground";case"INFO":return"text-blue-500 dark:text-blue-400";case"WARNING":return"text-yellow-600 dark:text-yellow-500";case"ERROR":return"text-red-600 dark:text-red-500";case"CRITICAL":return"text-red-700 dark:text-red-400 font-bold";default:return"text-foreground"}},L=Y=>{switch(Y){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"}},me=()=>{window.location.reload()},Ne=()=>{Qn.clearLogs(),l([])},je=()=>{const Y=pe.map(G=>`${G.timestamp} [${G.level.padEnd(8)}] [${G.module}] ${G.message}`).join(` `),we=new Blob([Y],{type:"text/plain;charset=utf-8"}),fe=URL.createObjectURL(we),Ee=document.createElement("a");Ee.href=fe,Ee.download=`logs-${Em(new Date,"yyyy-MM-dd-HHmmss")}.txt`,Ee.click(),URL.revokeObjectURL(fe)},ce=()=>{y(!b)},ge=()=>{g(void 0),j(void 0)},pe=u.useMemo(()=>a.filter(Y=>{const we=r===""||Y.message.toLowerCase().includes(r.toLowerCase())||Y.module.toLowerCase().includes(r.toLowerCase()),fe=d==="all"||Y.level===d,Ee=h==="all"||Y.module===h;let G=!0;if(p||N){const $=new Date(Y.timestamp);if(p){const A=new Date(p);A.setHours(0,0,0,0),G=G&&$>=A}if(N){const A=new Date(N);A.setHours(23,59,59,999),G=G&&$<=A}}return we&&fe&&Ee&&G}),[a,r,d,h,p,N]),D=Uo[M].rowHeight+F,Q=aw({count:pe.length,getScrollElement:()=>H.current,estimateSize:()=>D,overscan:50}),B=u.useRef(!1),ue=u.useRef(pe.length);return u.useEffect(()=>{const Y=H.current;if(!Y)return;const we=()=>{if(B.current)return;const{scrollTop:fe,scrollHeight:Ee,clientHeight:G}=Y,$=Ee-fe-G;$>100&&b?y(!1):$<50&&!b&&y(!0)};return Y.addEventListener("scroll",we,{passive:!0}),()=>Y.removeEventListener("scroll",we)},[b]),u.useEffect(()=>{const Y=pe.length>ue.current;ue.current=pe.length,b&&pe.length>0&&Y&&(B.current=!0,Q.scrollToIndex(pe.length-1,{align:"end",behavior:"auto"}),requestAnimationFrame(()=>{requestAnimationFrame(()=>{B.current=!1})}))},[pe.length,b,Q]),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",w?"bg-green-500 animate-pulse":"bg-red-500")}),e.jsx("span",{className:"text-xs text-muted-foreground",children:w?"已连接":"未连接"})]})]}),e.jsx(Te,{className:"p-2 sm:p-3",children:e.jsx(xc,{open:C,onOpenChange:R,children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"flex-1 relative min-w-0",children:[e.jsx($t,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),e.jsx(ne,{placeholder:"搜索日志...",value:r,onChange:Y=>c(Y.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:ce,className:"h-8 px-2",title:b?"自动滚动":"已暂停",children:[b?e.jsx(F1,{className:"h-3.5 w-3.5"}):e.jsx(H1,{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(os,{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(na,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"ml-1 text-xs hidden lg:inline",children:"导出"})]}),e.jsx(hc,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"sm",className:"h-8 px-2",title:C?"收起筛选":"展开筛选",children:[e.jsx(Po,{className:"h-3.5 w-3.5"}),C?e.jsx(Xr,{className:"h-3.5 w-3.5 ml-1"}):e.jsx(Ba,{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:[pe.length," / ",a.length]}),e.jsx("span",{className:"ml-1",children:"条日志"})]}),e.jsxs(fc,{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:gap-2",children:[e.jsxs(Pe,{value:d,onValueChange:m,children:[e.jsxs(Be,{className:"w-full sm:flex-1 h-8 text-xs",children:[e.jsx(Po,{className:"h-3.5 w-3.5 mr-1.5"}),e.jsx(Fe,{placeholder:"级别"})]}),e.jsxs(Ie,{children:[e.jsx(W,{value:"all",children:"全部级别"}),e.jsx(W,{value:"DEBUG",children:"DEBUG"}),e.jsx(W,{value:"INFO",children:"INFO"}),e.jsx(W,{value:"WARNING",children:"WARNING"}),e.jsx(W,{value:"ERROR",children:"ERROR"}),e.jsx(W,{value:"CRITICAL",children:"CRITICAL"})]})]}),e.jsxs(Pe,{value:h,onValueChange:f,children:[e.jsxs(Be,{className:"w-full sm:flex-1 h-8 text-xs",children:[e.jsx(Po,{className:"h-3.5 w-3.5 mr-1.5"}),e.jsx(Fe,{placeholder:"模块"})]}),e.jsxs(Ie,{children:[e.jsx(W,{value:"all",children:"全部模块"}),O.map(Y=>e.jsx(W,{value:Y,children:Y},Y))]})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:gap-2",children:[e.jsxs(cl,{children:[e.jsx(ol,{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(Ko,{className:"mr-1.5 h-3.5 w-3.5"}),e.jsx("span",{className:"text-xs",children:p?Em(p,"PP",{locale:Oo}):"开始日期"})]})}),e.jsx(tl,{className:"w-auto p-0",align:"start",children:e.jsx(aj,{mode:"single",selected:p,onSelect:g,initialFocus:!0,locale:Oo})})]}),e.jsxs(cl,{children:[e.jsx(ol,{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(Ko,{className:"mr-1.5 h-3.5 w-3.5"}),e.jsx("span",{className:"text-xs",children:N?Em(N,"PP",{locale:Oo}):"结束日期"})]})}),e.jsx(tl,{className:"w-auto p-0",align:"start",children:e.jsx(aj,{mode:"single",selected:N,onSelect:j,initialFocus:!0,locale:Oo})})]}),(p||N)&&e.jsxs(_,{variant:"outline",size:"sm",onClick:ge,className:"w-full sm:w-auto h-8",children:[e.jsx(Sa,{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(q1,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:"字号"})]}),e.jsx("div",{className:"flex gap-1",children:Object.keys(Uo).map(Y=>e.jsx(_,{variant:M===Y?"default":"outline",size:"sm",onClick:()=>S(Y),className:"h-6 px-2 text-xs",children:Uo[Y].label},Y))})]}),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(el,{value:[F],onValueChange:([Y])=>E(Y),min:0,max:12,step:2,className:"flex-1"}),e.jsxs("span",{className:"text-xs text-muted-foreground w-7",children:[F,"px"]})]}),e.jsxs("div",{className:"flex gap-2 sm:hidden",children:[e.jsxs(_,{variant:"outline",size:"sm",onClick:me,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(na,{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(Te,{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",Uo[M].class),style:{height:`${Q.getTotalSize()}px`},children:pe.length===0?e.jsx("div",{className:"text-gray-500 dark:text-gray-600 text-center py-8 text-xs sm:text-sm",children:"暂无日志数据"}):Q.getVirtualItems().map(Y=>{const we=pe[Y.index];return e.jsxs("div",{"data-index":Y.index,ref:Q.measureElement,className:P("absolute top-0 left-0 w-full px-2 sm:px-3 rounded hover:bg-white/5 transition-colors",L(we.level)),style:{transform:`translateY(${Y.start}px)`,paddingTop:`${F/2}px`,paddingBottom:`${F/2}px`},children:[e.jsxs("div",{className:"flex flex-col gap-0.5 sm:hidden",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-gray-500 dark:text-gray-600 text-[10px]",children:we.timestamp}),e.jsxs("span",{className:P("font-semibold text-[10px]",X(we.level)),children:["[",we.level,"]"]})]}),e.jsx("div",{className:"text-cyan-400 dark:text-cyan-500 truncate text-[10px]",children:we.module}),e.jsx("div",{className:"text-gray-300 dark:text-gray-400 whitespace-pre-wrap break-words text-[10px]",children:we.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:we.timestamp}),e.jsxs("span",{className:P("flex-shrink-0 w-[65px] lg:w-[75px] font-semibold",X(we.level)),children:["[",we.level,"]"]}),e.jsx("span",{className:"text-cyan-400 dark:text-cyan-500 flex-shrink-0 w-[100px] lg:w-[130px] truncate",children:we.module}),e.jsx("span",{className:"text-gray-300 dark:text-gray-400 flex-1 whitespace-pre-wrap break-words",children:we.message})]})]},Y.key)})})})})})]})}async function Gk(){return(await ke("/api/planner/overview")).json()}async function Kk(a,l=1,r=20,c){const d=new URLSearchParams({page:l.toString(),page_size:r.toString()});return c&&d.append("search",c),(await ke(`/api/planner/chat/${a}/logs?${d}`)).json()}async function Qk(a,l){return(await ke(`/api/planner/log/${a}/${l}`)).json()}async function Yk(){return(await ke("/api/replier/overview")).json()}async function Jk(a,l=1,r=20,c){const d=new URLSearchParams({page:l.toString(),page_size:r.toString()});return c&&d.append("search",c),(await ke(`/api/replier/chat/${a}/logs?${d}`)).json()}async function Xk(a,l){return(await ke(`/api/replier/log/${a}/${l}`)).json()}function mN(){const[a,l]=u.useState(new Map),[r,c]=u.useState(!0),d=u.useCallback(async()=>{try{c(!0);const h=await gx();if(h?.data){const f=new Map;h.data.forEach(p=>{f.set(p.chat_id,p.chat_name)}),l(f)}}catch(h){console.error("加载聊天列表失败:",h)}finally{c(!1)}},[]);u.useEffect(()=>{d()},[d]);const m=u.useCallback(h=>a.get(h)||h,[a]);return{chatNameMap:a,getChatName:m,loading:r,reload:d}}function Zo(a){return new Date(a*1e3).toLocaleString("zh-CN")}function xN(a){const r=Date.now()/1e3-a;return r<60?"刚刚":r<3600?`${Math.floor(r/60)} 分钟前`:r<86400?`${Math.floor(r/3600)} 小时前`:`${Math.floor(r/86400)} 天前`}function hN(a,l,r=1e4){u.useEffect(()=>{if(!a)return;const c=setInterval(l,r);return()=>clearInterval(c)},[a,l,r])}function Zk({autoRefresh:a,refreshKey:l}){const[r,c]=u.useState("overview"),[d,m]=u.useState(null),{getChatName:h}=mN(),[f,p]=u.useState(null),[g,N]=u.useState(!0),[j,b]=u.useState(null),[y,w]=u.useState(!1),[z,M]=u.useState(1),[S,F]=u.useState(20),[E,C]=u.useState(""),[R,H]=u.useState(""),[O,X]=u.useState(""),[L,me]=u.useState(null),[Ne,je]=u.useState(!1),[ce,ge]=u.useState(!1),pe=u.useCallback(async()=>{try{N(!0);const $=await Gk();p($)}catch($){console.error("加载规划器总览失败:",$)}finally{N(!1)}},[]),D=u.useCallback(async()=>{if(d)try{w(!0);const $=await Kk(d.chat_id,z,S,R||void 0);b($)}catch($){console.error("加载聊天日志失败:",$)}finally{w(!1)}},[d,z,S,R]);u.useEffect(()=>{pe()},[pe]),u.useEffect(()=>{l>0&&(r==="overview"?pe():D())},[l,r,pe,D]),u.useEffect(()=>{r==="chat-logs"&&d&&D()},[r,d,D]),hN(a,u.useCallback(()=>{r==="overview"?pe():D()},[r,pe,D]));const Q=$=>{m($),M(1),H(""),X(""),c("chat-logs")},B=()=>{c("overview"),m(null),b(null),H(""),X("")},ue=()=>{H(O),M(1)},Y=()=>{X(""),H(""),M(1)},we=async($,A)=>{try{ge(!0),je(!0);const K=await Qk($,A);me(K)}catch(K){console.error("加载计划详情失败:",K)}finally{ge(!1)}},fe=$=>{F(Number($)),M(1)},Ee=()=>{const $=parseInt(E),A=j?Math.ceil(j.total/j.page_size):0;!isNaN($)&&$>=1&&$<=A&&(M($),C(""))},G=j?Math.ceil(j.total/j.page_size):0;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"space-y-4",children:r==="overview"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(Te,{children:[e.jsxs(Oe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Ue,{className:"text-sm font-medium",children:"聊天数量"}),e.jsx(Ia,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(ze,{children:g?e.jsx(ks,{className:"h-8 w-16"}):e.jsx("div",{className:"text-2xl font-bold",children:f?.total_chats||0})})]}),e.jsxs(Te,{children:[e.jsxs(Oe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Ue,{className:"text-sm font-medium",children:"计划总数"}),e.jsx(rx,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(ze,{children:g?e.jsx(ks,{className:"h-8 w-16"}):e.jsx("div",{className:"text-2xl font-bold",children:f?.total_plans||0})})]})]}),e.jsxs(Te,{children:[e.jsxs(Oe,{children:[e.jsx(Ue,{children:"聊天列表"}),e.jsx(Ns,{children:"点击查看该聊天的所有计划记录"})]}),e.jsx(ze,{children:g?e.jsx("div",{className:"grid gap-3 md:grid-cols-2 lg:grid-cols-3",children:[...Array(6)].map(($,A)=>e.jsx(ks,{className:"h-24 w-full"},A))}):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($=>e.jsxs("div",{className:"border rounded-lg p-4 hover:bg-accent/50 transition-colors cursor-pointer",onClick:()=>Q($),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(Ia,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm truncate max-w-[180px]",title:h($.chat_id),children:h($.chat_id)})]}),e.jsx(Ce,{variant:"secondary",children:$.plan_count})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["最后活动: ",xN($.latest_timestamp)]})]},$.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:B,children:[e.jsx($a,{className:"h-4 w-4 mr-2"}),"返回聊天列表"]}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:["当前聊天: ",e.jsx("span",{className:"font-medium",children:d?h(d.chat_id):""}),e.jsx("span",{className:"mx-2",children:"•"}),"共 ",j?.total||0," 条计划记录"]})]}),e.jsxs(Te,{children:[e.jsxs(Oe,{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(Ue,{children:"计划执行记录"}),e.jsx(Ns,{children:d?h(d.chat_id):""})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-stretch sm:items-center gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ne,{placeholder:"搜索提示词内容...",value:O,onChange:$=>X($.target.value),onKeyDown:$=>$.key==="Enter"&&ue(),className:"w-full sm:w-48"}),e.jsx(_,{variant:"outline",size:"icon",onClick:ue,children:e.jsx($t,{className:"h-4 w-4"})}),R&&e.jsx(_,{variant:"ghost",size:"sm",onClick:Y,children:"清除"})]}),e.jsxs(Pe,{value:S.toString(),onValueChange:fe,children:[e.jsx(Be,{className:"w-full sm:w-32",children:e.jsx(Fe,{})}),e.jsxs(Ie,{children:[e.jsx(W,{value:"10",children:"10条/页"}),e.jsx(W,{value:"20",children:"20条/页"}),e.jsx(W,{value:"50",children:"50条/页"}),e.jsx(W,{value:"100",children:"100条/页"})]})]})]})]}),R&&e.jsxs("div",{className:"text-sm text-muted-foreground mt-2",children:["搜索关键词: ",e.jsxs("span",{className:"font-medium",children:['"',R,'"']})]})]}),e.jsx(ze,{children:y?e.jsx("div",{className:"space-y-2",children:[...Array(5)].map(($,A)=>e.jsx(ks,{className:"h-20 w-full"},A))}):j?.data&&j.data.length>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"space-y-2",children:j.data.map($=>e.jsxs("div",{className:"border rounded-lg p-3 hover:bg-accent/50 transition-colors cursor-pointer",onClick:()=>we($.chat_id,$.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:Zo($.timestamp)}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsxs(Ce,{variant:"secondary",className:"text-xs",children:[$.action_count," 个动作"]}),e.jsxs(Ce,{variant:"outline",className:"text-xs",children:[$.total_plan_ms.toFixed(0),"ms"]})]})]}),$.action_types&&$.action_types.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1 mb-2",children:$.action_types.map((A,K)=>e.jsx(Ce,{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:A},K))}),e.jsx("p",{className:"text-sm line-clamp-2",children:$.reasoning_preview||"无推理内容"})]},$.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:["共 ",j.total," 条记录,第 ",z," / ",G," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>M(1),disabled:z===1,className:"hidden sm:flex",children:e.jsx(kn,{className:"h-4 w-4"})}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>M($=>Math.max(1,$-1)),disabled:z===1,children:e.jsx(Pa,{className:"h-4 w-4"})}),e.jsxs("div",{className:"hidden sm:flex items-center gap-2",children:[e.jsx(ne,{type:"number",min:1,max:G,value:E,onChange:$=>C($.target.value),onKeyDown:$=>$.key==="Enter"&&Ee(),placeholder:"跳转",className:"w-20 h-8"}),e.jsx(_,{size:"sm",variant:"outline",onClick:Ee,children:"跳转"})]}),e.jsxs("span",{className:"sm:hidden text-sm text-muted-foreground",children:[z,"/",G]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>M($=>Math.min(G,$+1)),disabled:z===G,children:e.jsx(ra,{className:"h-4 w-4"})}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>M(G),disabled:z===G,className:"hidden sm:flex",children:e.jsx(Cn,{className:"h-4 w-4"})})]})]})]}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无计划记录"})})]})]})}),e.jsx(Qs,{open:Ne,onOpenChange:je,children:e.jsxs(Hs,{className:"max-w-4xl max-h-[80vh] grid grid-rows-[auto_1fr_auto] overflow-hidden",children:[e.jsxs(qs,{children:[e.jsxs(Vs,{className:"flex items-center gap-2",children:[e.jsx(Ua,{className:"h-5 w-5"}),"计划执行详情"]}),e.jsx(at,{children:"查看麦麦的详细计划推理过程和执行动作"})]}),e.jsx(ts,{className:"h-full pr-4",children:e.jsx("div",{className:"space-y-6 pb-4",children:ce?e.jsx("div",{className:"space-y-4",children:[...Array(5)].map(($,A)=>e.jsx(ks,{className:"h-24 w-full"},A))}):L?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(da,{className:"h-4 w-4"}),"基本信息"]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4 p-4 bg-muted/50 rounded-lg",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"聊天"}),e.jsx("div",{className:"text-sm",title:L.chat_id,children:h(L.chat_id)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"时间戳"}),e.jsx("div",{className:"text-sm",children:Zo(L.timestamp)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"类型"}),e.jsx(Ce,{variant:"outline",children:L.type})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"动作数量"}),e.jsxs(Ce,{children:[L.actions.length," 个动作"]})]})]})]}),e.jsx(la,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(sl,{className:"h-4 w-4"}),"性能统计"]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsxs(Te,{children:[e.jsx(Oe,{className:"p-4 pb-2",children:e.jsx(Ue,{className:"text-xs text-muted-foreground",children:"提示词构建"})}),e.jsx(ze,{className:"p-4 pt-0",children:e.jsxs("div",{className:"text-xl font-bold",children:[L.timing.prompt_build_ms?.toFixed(2)||0,"ms"]})})]}),e.jsxs(Te,{children:[e.jsx(Oe,{className:"p-4 pb-2",children:e.jsx(Ue,{className:"text-xs text-muted-foreground",children:"LLM 推理"})}),e.jsx(ze,{className:"p-4 pt-0",children:e.jsxs("div",{className:"text-xl font-bold",children:[L.timing.llm_duration_ms?.toFixed(2)||0,"ms"]})})]}),e.jsxs(Te,{children:[e.jsx(Oe,{className:"p-4 pb-2",children:e.jsx(Ue,{className:"text-xs text-muted-foreground",children:"总计划时间"})}),e.jsx(ze,{className:"p-4 pt-0",children:e.jsxs("div",{className:"text-xl font-bold",children:[L.timing.total_plan_ms?.toFixed(2)||0,"ms"]})})]})]})]}),e.jsx(la,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(hx,{className:"h-4 w-4"}),"推理过程"]}),e.jsx("div",{className:"p-4 bg-muted/50 rounded-lg",children:e.jsx("p",{className:"text-sm whitespace-pre-wrap leading-relaxed",children:L.reasoning||"无推理内容"})})]}),e.jsx(la,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(rv,{className:"h-4 w-4"}),"执行动作 (",L.actions.length,")"]}),e.jsx("div",{className:"space-y-3",children:L.actions.map(($,A)=>e.jsxs(Te,{children:[e.jsx(Oe,{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(Ce,{variant:"default",children:["动作 ",A+1]}),e.jsx(Ce,{variant:"outline",children:$.action_type})]})})}),e.jsxs(ze,{className:"p-4 pt-0 space-y-3",children:[$.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 $.reasoning=="string"?$.reasoning:JSON.stringify($.reasoning)})]}),$.action_message&&e.jsxs("div",{className:"overflow-hidden",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground mb-1",children:"动作消息"}),typeof $.action_message=="string"?e.jsx("p",{className:"text-sm bg-muted/30 p-2 rounded break-all whitespace-pre-wrap",children:$.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($.action_message,null,2)})]}),$.action_data&&Object.keys($.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($.action_data,null,2)})]}),$.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 $.action_reasoning=="string"?$.action_reasoning:JSON.stringify($.action_reasoning)})]})]})]},A))})]}),e.jsx(la,{}),L.raw_output&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"原始输出"}),e.jsxs("details",{className:"group",children:[e.jsx("summary",{className:"cursor-pointer text-sm text-muted-foreground hover:text-foreground",children:"点击展开查看完整原始输出"}),e.jsx("div",{className:"mt-2 p-4 bg-muted/50 rounded-lg",children:e.jsx("pre",{className:"text-xs whitespace-pre-wrap break-words",children:L.raw_output})})]})]}),L.prompt&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"完整提示词"}),e.jsxs("details",{className:"group",children:[e.jsx("summary",{className:"cursor-pointer text-sm text-muted-foreground hover:text-foreground",children:"点击展开查看完整提示词"}),e.jsx("div",{className:"mt-2 p-4 bg-muted/50 rounded-lg",children:e.jsx("pre",{className:"text-xs whitespace-pre-wrap break-words",children:L.prompt})})]})]})]}):e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx("p",{className:"text-muted-foreground",children:"无数据"})})})}),e.jsx(gt,{className:"flex-shrink-0",children:e.jsx(_,{onClick:()=>je(!1),children:"关闭"})})]})})]})}function Wk({autoRefresh:a,refreshKey:l}){const[r,c]=u.useState("overview"),[d,m]=u.useState(null),{getChatName:h}=mN(),[f,p]=u.useState(null),[g,N]=u.useState(!0),[j,b]=u.useState(null),[y,w]=u.useState(!1),[z,M]=u.useState(1),[S,F]=u.useState(20),[E,C]=u.useState(""),[R,H]=u.useState(""),[O,X]=u.useState(""),[L,me]=u.useState(null),[Ne,je]=u.useState(!1),[ce,ge]=u.useState(!1),pe=u.useCallback(async()=>{try{N(!0);const $=await Yk();p($)}catch($){console.error("加载回复器总览失败:",$)}finally{N(!1)}},[]),D=u.useCallback(async()=>{if(d)try{w(!0);const $=await Jk(d.chat_id,z,S,R||void 0);b($)}catch($){console.error("加载聊天日志失败:",$)}finally{w(!1)}},[d,z,S,R]);u.useEffect(()=>{pe()},[pe]),u.useEffect(()=>{l>0&&(r==="overview"?pe():D())},[l,r,pe,D]),u.useEffect(()=>{r==="chat-logs"&&d&&D()},[r,d,D]),hN(a,u.useCallback(()=>{r==="overview"?pe():D()},[r,pe,D]));const Q=$=>{m($),M(1),H(""),X(""),c("chat-logs")},B=()=>{c("overview"),m(null),b(null),H(""),X("")},ue=()=>{H(O),M(1)},Y=()=>{X(""),H(""),M(1)},we=async($,A)=>{try{ge(!0),je(!0);const K=await Xk($,A);me(K)}catch(K){console.error("加载回复详情失败:",K)}finally{ge(!1)}},fe=$=>{F(Number($)),M(1)},Ee=()=>{const $=parseInt(E),A=j?Math.ceil(j.total/j.page_size):0;!isNaN($)&&$>=1&&$<=A&&(M($),C(""))},G=j?Math.ceil(j.total/j.page_size):0;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"space-y-4",children:r==="overview"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(Te,{children:[e.jsxs(Oe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Ue,{className:"text-sm font-medium",children:"聊天数量"}),e.jsx(Ia,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(ze,{children:g?e.jsx(ks,{className:"h-8 w-16"}):e.jsx("div",{className:"text-2xl font-bold",children:f?.total_chats||0})})]}),e.jsxs(Te,{children:[e.jsxs(Oe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Ue,{className:"text-sm font-medium",children:"回复总数"}),e.jsx(rx,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(ze,{children:g?e.jsx(ks,{className:"h-8 w-16"}):e.jsx("div",{className:"text-2xl font-bold",children:f?.total_replies||0})})]})]}),e.jsxs(Te,{children:[e.jsxs(Oe,{children:[e.jsx(Ue,{children:"聊天列表"}),e.jsx(Ns,{children:"点击查看该聊天的所有回复记录"})]}),e.jsx(ze,{children:g?e.jsx("div",{className:"grid gap-3 md:grid-cols-2 lg:grid-cols-3",children:[...Array(6)].map(($,A)=>e.jsx(ks,{className:"h-24 w-full"},A))}):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($=>e.jsxs("div",{className:"border rounded-lg p-4 hover:bg-accent/50 transition-colors cursor-pointer",onClick:()=>Q($),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(Ia,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm truncate max-w-[180px]",title:h($.chat_id),children:h($.chat_id)})]}),e.jsx(Ce,{variant:"secondary",children:$.reply_count})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["最后活动: ",xN($.latest_timestamp)]})]},$.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:B,children:[e.jsx($a,{className:"h-4 w-4 mr-2"}),"返回聊天列表"]}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:["当前聊天: ",e.jsx("span",{className:"font-medium",children:d?h(d.chat_id):""}),e.jsx("span",{className:"mx-2",children:"•"}),"共 ",j?.total||0," 条回复记录"]})]}),e.jsxs(Te,{children:[e.jsxs(Oe,{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(Ue,{children:"回复生成记录"}),e.jsx(Ns,{children:d?h(d.chat_id):""})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-stretch sm:items-center gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ne,{placeholder:"搜索提示词内容...",value:O,onChange:$=>X($.target.value),onKeyDown:$=>$.key==="Enter"&&ue(),className:"w-full sm:w-48"}),e.jsx(_,{variant:"outline",size:"icon",onClick:ue,children:e.jsx($t,{className:"h-4 w-4"})}),R&&e.jsx(_,{variant:"ghost",size:"sm",onClick:Y,children:"清除"})]}),e.jsxs(Pe,{value:S.toString(),onValueChange:fe,children:[e.jsx(Be,{className:"w-full sm:w-32",children:e.jsx(Fe,{})}),e.jsxs(Ie,{children:[e.jsx(W,{value:"10",children:"10条/页"}),e.jsx(W,{value:"20",children:"20条/页"}),e.jsx(W,{value:"50",children:"50条/页"}),e.jsx(W,{value:"100",children:"100条/页"})]})]})]})]}),R&&e.jsxs("div",{className:"text-sm text-muted-foreground mt-2",children:["搜索关键词: ",e.jsxs("span",{className:"font-medium",children:['"',R,'"']})]})]}),e.jsx(ze,{children:y?e.jsx("div",{className:"space-y-2",children:[...Array(5)].map(($,A)=>e.jsx(ks,{className:"h-20 w-full"},A))}):j?.data&&j.data.length>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"space-y-2",children:j.data.map($=>e.jsxs("div",{className:"border rounded-lg p-3 hover:bg-accent/50 transition-colors cursor-pointer",onClick:()=>we($.chat_id,$.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:Zo($.timestamp)}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[$.success?e.jsxs(Ce,{variant:"default",className:"text-xs bg-green-600",children:[e.jsx(Mg,{className:"h-3 w-3 mr-1"}),"成功"]}):e.jsxs(Ce,{variant:"destructive",className:"text-xs",children:[e.jsx(ta,{className:"h-3 w-3 mr-1"}),"失败"]}),e.jsx(Ce,{variant:"outline",className:"text-xs",children:$.model}),e.jsxs(Ce,{variant:"secondary",className:"text-xs",children:[$.overall_ms.toFixed(0),"ms"]})]})]}),e.jsx("p",{className:"text-sm line-clamp-2",children:$.output_preview||"无输出内容"})]},$.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:["共 ",j.total," 条记录,第 ",z," / ",G," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>M(1),disabled:z===1,className:"hidden sm:flex",children:e.jsx(kn,{className:"h-4 w-4"})}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>M($=>Math.max(1,$-1)),disabled:z===1,children:e.jsx(Pa,{className:"h-4 w-4"})}),e.jsxs("div",{className:"hidden sm:flex items-center gap-2",children:[e.jsx(ne,{type:"number",min:1,max:G,value:E,onChange:$=>C($.target.value),onKeyDown:$=>$.key==="Enter"&&Ee(),placeholder:"跳转",className:"w-20 h-8"}),e.jsx(_,{size:"sm",variant:"outline",onClick:Ee,children:"跳转"})]}),e.jsxs("span",{className:"sm:hidden text-sm text-muted-foreground",children:[z,"/",G]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>M($=>Math.min(G,$+1)),disabled:z===G,children:e.jsx(ra,{className:"h-4 w-4"})}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>M(G),disabled:z===G,className:"hidden sm:flex",children:e.jsx(Cn,{className:"h-4 w-4"})})]})]})]}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无回复记录"})})]})]})}),e.jsx(Qs,{open:Ne,onOpenChange:je,children:e.jsxs(Hs,{className:"max-w-4xl max-h-[80vh] grid grid-rows-[auto_1fr_auto] overflow-hidden",children:[e.jsxs(qs,{children:[e.jsxs(Vs,{className:"flex items-center gap-2",children:[e.jsx(Ua,{className:"h-5 w-5"}),"回复生成详情"]}),e.jsx(at,{children:"查看麦麦的详细回复生成过程"})]}),e.jsx(ts,{className:"h-full pr-4",children:e.jsx("div",{className:"space-y-6 pb-4",children:ce?e.jsx("div",{className:"space-y-4",children:[...Array(5)].map(($,A)=>e.jsx(ks,{className:"h-24 w-full"},A))}):L?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(da,{className:"h-4 w-4"}),"基本信息"]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4 p-4 bg-muted/50 rounded-lg",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"聊天"}),e.jsx("div",{className:"text-sm",title:L.chat_id,children:h(L.chat_id)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"时间戳"}),e.jsx("div",{className:"text-sm",children:Zo(L.timestamp)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"状态"}),L.success?e.jsxs(Ce,{variant:"default",className:"bg-green-600",children:[e.jsx(Mg,{className:"h-3 w-3 mr-1"}),"成功"]}):e.jsxs(Ce,{variant:"destructive",children:[e.jsx(ta,{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(Ce,{variant:"outline",children:["Level ",L.think_level]})]})]})]}),e.jsx(la,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(V1,{className:"h-4 w-4"}),"模型信息"]}),e.jsx("div",{className:"p-4 bg-muted/50 rounded-lg",children:e.jsx(Ce,{variant:"secondary",className:"text-sm",children:L.model})})]}),e.jsx(la,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(sl,{className:"h-4 w-4"}),"性能统计"]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsxs(Te,{children:[e.jsx(Oe,{className:"p-4 pb-2",children:e.jsx(Ue,{className:"text-xs text-muted-foreground",children:"提示词构建"})}),e.jsx(ze,{className:"p-4 pt-0",children:e.jsxs("div",{className:"text-xl font-bold",children:[L.timing.prompt_ms?.toFixed(2)||0,"ms"]})})]}),e.jsxs(Te,{children:[e.jsx(Oe,{className:"p-4 pb-2",children:e.jsx(Ue,{className:"text-xs text-muted-foreground",children:"LLM 推理"})}),e.jsx(ze,{className:"p-4 pt-0",children:e.jsxs("div",{className:"text-xl font-bold",children:[L.timing.llm_ms?.toFixed(2)||0,"ms"]})})]}),e.jsxs(Te,{children:[e.jsx(Oe,{className:"p-4 pb-2",children:e.jsx(Ue,{className:"text-xs text-muted-foreground",children:"总耗时"})}),e.jsx(ze,{className:"p-4 pt-0",children:e.jsxs("div",{className:"text-xl font-bold",children:[L.timing.overall_ms?.toFixed(2)||0,"ms"]})})]})]}),L.timing.timing_logs&&L.timing.timing_logs.length>0&&e.jsxs("div",{className:"mt-3 p-3 bg-muted/30 rounded-lg",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground mb-2",children:"耗时详情"}),e.jsx("div",{className:"space-y-1",children:L.timing.timing_logs.map(($,A)=>e.jsx("div",{className:"text-xs text-muted-foreground",children:$},A))})]}),L.timing.almost_zero&&e.jsxs("div",{className:"mt-2 text-xs text-muted-foreground",children:[e.jsx("span",{className:"font-medium",children:"近乎零耗时: "}),L.timing.almost_zero]})]}),e.jsx(la,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(hx,{className:"h-4 w-4"}),"回复输出"]}),e.jsx("div",{className:"p-4 bg-muted/50 rounded-lg",children:e.jsx("p",{className:"text-sm whitespace-pre-wrap leading-relaxed",children:L.output||"无输出内容"})})]}),L.processed_output&&L.processed_output.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(la,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"处理后的输出"}),e.jsx("div",{className:"space-y-2",children:L.processed_output.map(($,A)=>e.jsx("div",{className:"p-3 bg-muted/30 rounded-lg",children:e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:$})},A))})]})]}),L.reasoning&&e.jsxs(e.Fragment,{children:[e.jsx(la,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"推理过程"}),e.jsx("div",{className:"p-4 bg-muted/50 rounded-lg",children:e.jsx("p",{className:"text-sm whitespace-pre-wrap leading-relaxed",children:L.reasoning})})]})]}),L.error&&e.jsxs(e.Fragment,{children:[e.jsx(la,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-destructive",children:"错误信息"}),e.jsx("div",{className:"p-4 bg-destructive/10 rounded-lg border border-destructive/20",children:e.jsx("p",{className:"text-sm text-destructive whitespace-pre-wrap",children:L.error})})]})]}),L.prompt&&e.jsxs(e.Fragment,{children:[e.jsx(la,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"完整提示词"}),e.jsxs("details",{className:"group",children:[e.jsx("summary",{className:"cursor-pointer text-sm text-muted-foreground hover:text-foreground",children:"点击展开查看完整提示词"}),e.jsx("div",{className:"mt-2 p-4 bg-muted/50 rounded-lg",children:e.jsx("pre",{className:"text-xs whitespace-pre-wrap break-words",children:L.prompt})})]})]})]})]}):e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx("p",{className:"text-muted-foreground",children:"无数据"})})})}),e.jsx(gt,{className:"flex-shrink-0",children:e.jsx(_,{onClick:()=>je(!1),children:"关闭"})})]})})]})}function eC(){const[a,l]=u.useState("planner"),[r,c]=u.useState(!1),[d,m]=u.useState(0),h=u.useCallback(()=>{m(f=>f+1)},[]);return e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"计划器 & 回复器监控"}),e.jsx("p",{className:"text-muted-foreground mt-1 sm:mt-2 text-sm sm:text-base",children:"实时监控麦麦的任务计划器和回复生成器运行状态"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(_,{variant:r?"default":"outline",size:"sm",onClick:()=>c(!r),children:[e.jsx(dt,{className:`h-4 w-4 mr-2 ${r?"animate-spin":""}`}),r?"自动刷新中":"自动刷新"]}),e.jsx(_,{variant:"outline",size:"sm",onClick:h,children:e.jsx(dt,{className:"h-4 w-4"})})]})]}),e.jsxs(Jt,{value:a,onValueChange:f=>l(f),className:"w-full",children:[e.jsxs(Gt,{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(nx,{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(G1,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"回复器监控"})]})]}),e.jsxs(ts,{className:"h-[calc(100vh-240px)] sm:h-[calc(100vh-280px)] mt-4 sm:mt-6",children:[e.jsx(Ss,{value:"planner",className:"mt-0",children:e.jsx(Zk,{autoRefresh:r,refreshKey:d})}),e.jsx(Ss,{value:"replier",className:"mt-0",children:e.jsx(Wk,{autoRefresh:r,refreshKey:d})})]})]})]})}const sC="Mai-with-u",tC="plugin-repo",aC="main",lC="plugin_details.json";async function nC(){try{const a=await ke("/api/webui/plugins/fetch-raw",{method:"POST",body:JSON.stringify({owner:sC,repo:tC,branch:aC,file_path:lC})});if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);const l=await a.json();if(!l.success||!l.data)throw new Error(l.error||"获取插件列表失败");return JSON.parse(l.data).filter(d=>!d?.id||!d?.manifest?(console.warn("跳过无效插件数据:",d),!1):!d.manifest.name||!d.manifest.version?(console.warn("跳过缺少必需字段的插件:",d.id),!1):!0).map(d=>({id:d.id,manifest:{manifest_version:d.manifest.manifest_version||1,name:d.manifest.name,version:d.manifest.version,description:d.manifest.description||"",author:d.manifest.author||{name:"Unknown"},license:d.manifest.license||"Unknown",host_application:d.manifest.host_application||{min_version:"0.0.0"},homepage_url:d.manifest.homepage_url,repository_url:d.manifest.repository_url,keywords:d.manifest.keywords||[],categories:d.manifest.categories||[],default_locale:d.manifest.default_locale||"zh-CN",locales_path:d.manifest.locales_path},downloads:0,rating:0,review_count:0,installed:!1,published_at:new Date().toISOString(),updated_at:new Date().toISOString()}))}catch(a){throw console.error("Failed to fetch plugin list:",a),a}}async function fN(){try{const a=await ke("/api/webui/plugins/git-status");if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);return await a.json()}catch(a){return console.error("Failed to check Git status:",a),{installed:!1,error:"无法检测 Git 安装状态"}}}async function pN(){try{const a=await ke("/api/webui/plugins/version");if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);return await a.json()}catch(a){return console.error("Failed to get Maimai version:",a),{version:"0.0.0",version_major:0,version_minor:0,version_patch:0}}}function gN(a,l,r){const c=a.split(".").map(f=>parseInt(f)||0),d=c[0]||0,m=c[1]||0,h=c[2]||0;if(r.version_majorparseInt(j)||0),p=f[0]||0,g=f[1]||0,N=f[2]||0;if(r.version_major>p||r.version_major===p&&r.version_minor>g||r.version_major===p&&r.version_minor===g&&r.version_patch>N)return!1}return!0}async function rC(){try{const a=await ke("/api/webui/ws-token");if(!a.ok)return console.error("获取 WebSocket token 失败:",a.status),null;const l=await a.json();return l.success&&l.token?l.token:null}catch(a){return console.error("获取 WebSocket token 失败:",a),null}}async function iC(a,l){const r=await rC();if(!r)return console.warn("无法获取 WebSocket token,可能未登录"),null;const c=window.location.protocol==="https:"?"wss:":"ws:",d=window.location.host,m=`${c}//${d}/api/webui/ws/plugin-progress?token=${encodeURIComponent(r)}`;try{const h=new WebSocket(m);return h.onopen=()=>{console.log("Plugin progress WebSocket connected");const f=setInterval(()=>{h.readyState===WebSocket.OPEN?h.send("ping"):clearInterval(f)},3e4)},h.onmessage=f=>{try{if(f.data==="pong")return;const p=JSON.parse(f.data);a(p)}catch(p){console.error("Failed to parse progress data:",p)}},h.onerror=f=>{console.error("Plugin progress WebSocket error:",f),l?.(f)},h.onclose=()=>{console.log("Plugin progress WebSocket disconnected")},h}catch(h){return console.error("创建 WebSocket 连接失败:",h),null}}async function Il(){try{const a=await ke("/api/webui/plugins/installed",{headers:Zs()});if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);const l=await a.json();if(!l.success)throw new Error(l.message||"获取已安装插件列表失败");return l.plugins||[]}catch(a){return console.error("Failed to get installed plugins:",a),[]}}function bn(a,l){return l.some(r=>r.id===a)}function yn(a,l){const r=l.find(c=>c.id===a);if(r)return r.manifest?.version||r.version}async function jN(a,l,r="main"){const c=await ke("/api/webui/plugins/install",{method:"POST",body:JSON.stringify({plugin_id:a,repository_url:l,branch:r})});if(!c.ok){const d=await c.json();throw new Error(d.detail||"安装失败")}return await c.json()}async function vN(a){const l=await ke("/api/webui/plugins/uninstall",{method:"POST",body:JSON.stringify({plugin_id:a})});if(!l.ok){const r=await l.json();throw new Error(r.detail||"卸载失败")}return await l.json()}async function NN(a,l,r="main"){const c=await ke("/api/webui/plugins/update",{method:"POST",body:JSON.stringify({plugin_id:a,repository_url:l,branch:r})});if(!c.ok){const d=await c.json();throw new Error(d.detail||"更新失败")}return await c.json()}async function cC(a){const l=await ke(`/api/webui/plugins/config/${a}/schema`,{headers:Zs()});if(!l.ok){const c=await l.text();try{const d=JSON.parse(c);throw new Error(d.detail||"获取配置 Schema 失败")}catch{throw new Error(`获取配置 Schema 失败 (${l.status})`)}}const r=await l.json();if(!r.success)throw new Error(r.message||"获取配置 Schema 失败");return r.schema}async function oC(a){const l=await ke(`/api/webui/plugins/config/${a}`,{headers:Zs()});if(!l.ok){const c=await l.text();try{const d=JSON.parse(c);throw new Error(d.detail||"获取配置失败")}catch{throw new Error(`获取配置失败 (${l.status})`)}}const r=await l.json();if(!r.success)throw new Error(r.message||"获取配置失败");return r.config}async function dC(a){const l=await ke(`/api/webui/plugins/config/${a}/raw`,{headers:Zs()});if(!l.ok){const c=await l.text();try{const d=JSON.parse(c);throw new Error(d.detail||"获取配置失败")}catch{throw new Error(`获取配置失败 (${l.status})`)}}const r=await l.json();if(!r.success)throw new Error(r.message||"获取配置失败");return r.config}async function uC(a,l){const r=await ke(`/api/webui/plugins/config/${a}`,{method:"PUT",headers:Zs(),body:JSON.stringify({config:l})});if(!r.ok){const c=await r.json();throw new Error(c.detail||"保存配置失败")}return await r.json()}async function mC(a,l){const r=await ke(`/api/webui/plugins/config/${a}/raw`,{method:"PUT",headers:Zs(),body:JSON.stringify({config:l})});if(!r.ok){const c=await r.json();throw new Error(c.detail||"保存配置失败")}return await r.json()}async function xC(a){const l=await ke(`/api/webui/plugins/config/${a}/reset`,{method:"POST",headers:Zs()});if(!l.ok){const r=await l.json();throw new Error(r.detail||"重置配置失败")}return await l.json()}async function hC(a){const l=await ke(`/api/webui/plugins/config/${a}/toggle`,{method:"POST",headers:Zs()});if(!l.ok){const r=await l.json();throw new Error(r.detail||"切换状态失败")}return await l.json()}const Nc="https://maibot-plugin-stats.maibot-webui.workers.dev";async function bN(a){try{const l=await fetch(`${Nc}/stats/${a}`);return l.ok?await l.json():(console.error("Failed to fetch plugin stats:",l.statusText),null)}catch(l){return console.error("Error fetching plugin stats:",l),null}}async function fC(a,l){try{const r=l||Ax(),c=await fetch(`${Nc}/stats/like`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:a,user_id:r})}),d=await c.json();return c.status===429?{success:!1,error:"操作过于频繁,请稍后再试"}:c.ok?{success:!0,...d}:{success:!1,error:d.error||"点赞失败"}}catch(r){return console.error("Error liking plugin:",r),{success:!1,error:"网络错误"}}}async function pC(a,l){try{const r=l||Ax(),c=await fetch(`${Nc}/stats/dislike`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:a,user_id:r})}),d=await c.json();return c.status===429?{success:!1,error:"操作过于频繁,请稍后再试"}:c.ok?{success:!0,...d}:{success:!1,error:d.error||"点踩失败"}}catch(r){return console.error("Error disliking plugin:",r),{success:!1,error:"网络错误"}}}async function gC(a,l,r,c){if(l<1||l>5)return{success:!1,error:"评分必须在 1-5 之间"};try{const d=c||Ax(),m=await fetch(`${Nc}/stats/rate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:a,rating:l,comment:r,user_id:d})}),h=await m.json();return m.status===429?{success:!1,error:"每天最多评分 3 次"}:m.ok?{success:!0,...h}:{success:!1,error:h.error||"评分失败"}}catch(d){return console.error("Error rating plugin:",d),{success:!1,error:"网络错误"}}}async function yN(a){try{const l=await fetch(`${Nc}/stats/download`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:a})}),r=await l.json();return l.status===429?(console.warn("Download recording rate limited"),{success:!0}):l.ok?{success:!0,...r}:(console.error("Failed to record download:",r.error),{success:!1,error:r.error})}catch(l){return console.error("Error recording download:",l),{success:!1,error:"网络错误"}}}function jC(){const a=navigator,l=[navigator.userAgent,navigator.language,navigator.languages?.join(",")||"",navigator.platform,navigator.hardwareConcurrency||0,screen.width,screen.height,screen.colorDepth,screen.pixelDepth,new Date().getTimezoneOffset(),Intl.DateTimeFormat().resolvedOptions().timeZone,navigator.maxTouchPoints||0,a.deviceMemory||0].join("|");let r=0;for(let c=0;c{const Z=J.map(async De=>{try{const xe=await bN(De.id);return{id:De.id,stats:xe}}catch(xe){return console.warn(`Failed to load stats for ${De.id}:`,xe),{id:De.id,stats:null}}}),Le=await Promise.all(Z),le={};Le.forEach(({id:De,stats:xe})=>{xe&&(le[De]=xe)}),L(le)};u.useEffect(()=>{let J=null,Z=!1;return(async()=>{if(J=await iC(le=>{Z||(C(le),le.stage==="success"?setTimeout(()=>{Z||C(null)},2e3):le.stage==="error"&&(w(!1),M(le.error||"加载失败")))},le=>{console.error("WebSocket error:",le),Z||fe({title:"WebSocket 连接失败",description:"无法实时显示加载进度",variant:"destructive"})}),await new Promise(le=>{if(!J){le();return}const De=()=>{J&&J.readyState===WebSocket.OPEN?(console.log("WebSocket connected, starting to load plugins"),le()):J&&J.readyState===WebSocket.CLOSED?(console.warn("WebSocket closed before loading plugins"),le()):setTimeout(De,100)};De()}),!Z){const le=await fN();F(le),le.installed||fe({title:"Git 未安装",description:le.error||"请先安装 Git 才能使用插件安装功能",variant:"destructive"})}if(!Z){const le=await pN();H(le)}if(!Z)try{w(!0),M(null);const le=await nC();if(!Z){const De=await Il();O(De);const xe=le.map(Me=>{const ds=bn(Me.id,De),Ts=yn(Me.id,De);return{...Me,installed:ds,installed_version:Ts}});for(const Me of De)!xe.some(Ts=>Ts.id===Me.id)&&Me.manifest&&xe.push({id:Me.id,manifest:{manifest_version:Me.manifest.manifest_version||1,name:Me.manifest.name,version:Me.manifest.version,description:Me.manifest.description||"",author:Me.manifest.author,license:Me.manifest.license||"Unknown",host_application:Me.manifest.host_application,homepage_url:Me.manifest.homepage_url,repository_url:Me.manifest.repository_url,keywords:Me.manifest.keywords||[],categories:Me.manifest.categories||[],default_locale:Me.manifest.default_locale||"zh-CN",locales_path:Me.manifest.locales_path},downloads:0,rating:0,review_count:0,installed:!0,installed_version:Me.manifest.version,published_at:new Date().toISOString(),updated_at:new Date().toISOString()});b(xe),Ee(xe)}}catch(le){if(!Z){const De=le instanceof Error?le.message:"加载插件列表失败";M(De),fe({title:"加载失败",description:De,variant:"destructive"})}}finally{Z||w(!1)}})(),()=>{Z=!0,J&&J.close()}},[fe]);const G=J=>{if(!J.installed&&R&&!$(J))return e.jsxs(Ce,{variant:"destructive",className:"gap-1",children:[e.jsx(Ut,{className:"h-3 w-3"}),"不兼容"]});if(J.installed){const Z=J.installed_version?.trim(),Le=J.manifest.version?.trim();if(Z!==Le){const le=Z?.split(".").map(Number)||[0,0,0],De=Le?.split(".").map(Number)||[0,0,0];for(let xe=0;xe<3;xe++){if((De[xe]||0)>(le[xe]||0))return e.jsxs(Ce,{variant:"outline",className:"gap-1 text-orange-600 border-orange-600",children:[e.jsx(Ut,{className:"h-3 w-3"}),"可更新"]});if((De[xe]||0)<(le[xe]||0))break}}return e.jsxs(Ce,{variant:"default",className:"gap-1",children:[e.jsx(st,{className:"h-3 w-3"}),"已安装"]})}return null},$=J=>!R||!J.manifest?.host_application?!0:gN(J.manifest.host_application.min_version,J.manifest.host_application.max_version,R),A=J=>{if(!J.installed||!J.installed_version||!J.manifest?.version)return!1;const Z=J.installed_version.trim(),Le=J.manifest.version.trim();if(Z===Le)return!1;const le=Z.split(".").map(Number),De=Le.split(".").map(Number);for(let xe=0;xe<3;xe++){if((De[xe]||0)>(le[xe]||0))return!0;if((De[xe]||0)<(le[xe]||0))return!1}return!1},K=j.filter(J=>{if(!J.manifest)return console.warn("[过滤] 跳过无 manifest 的插件:",J.id),!1;const Z=c===""||J.manifest.name?.toLowerCase().includes(c.toLowerCase())||J.manifest.description?.toLowerCase().includes(c.toLowerCase())||J.manifest.keywords&&J.manifest.keywords.some(xe=>xe.toLowerCase().includes(c.toLowerCase())),Le=m==="all"||J.manifest.categories&&J.manifest.categories.includes(m);let le=!0;f==="installed"?le=J.installed===!0:f==="updates"&&(le=J.installed===!0&&A(J));const De=!g||!R||$(J);return Z&&Le&&le&&De}),Re=J=>{if(!S?.installed){fe({title:"无法安装",description:"Git 未安装",variant:"destructive"});return}if(R&&!$(J)){fe({title:"无法安装",description:"插件与当前麦麦版本不兼容",variant:"destructive"});return}ce(J),pe("main"),Q(""),ue("preset"),we(!1),Ne(!0)},se=async()=>{if(!je)return;const J=B==="custom"?D:ge;if(!J||J.trim()===""){fe({title:"分支名称不能为空",variant:"destructive"});return}try{Ne(!1),await jN(je.id,je.manifest.repository_url||"",J),yN(je.id).catch(Le=>{console.warn("Failed to record download:",Le)}),fe({title:"安装成功",description:`${je.manifest.name} 已成功安装`});const Z=await Il();O(Z),b(Le=>Le.map(le=>{if(le.id===je.id){const De=bn(le.id,Z),xe=yn(le.id,Z);return{...le,installed:De,installed_version:xe}}return le}))}catch(Z){fe({title:"安装失败",description:Z instanceof Error?Z.message:"未知错误",variant:"destructive"})}finally{ce(null)}},$e=async J=>{try{await vN(J.id),fe({title:"卸载成功",description:`${J.manifest.name} 已成功卸载`});const Z=await Il();O(Z),b(Le=>Le.map(le=>{if(le.id===J.id){const De=bn(le.id,Z),xe=yn(le.id,Z);return{...le,installed:De,installed_version:xe}}return le}))}catch(Z){fe({title:"卸载失败",description:Z instanceof Error?Z.message:"未知错误",variant:"destructive"})}},cs=async J=>{if(!S?.installed){fe({title:"无法更新",description:"Git 未安装",variant:"destructive"});return}try{const Z=await NN(J.id,J.manifest.repository_url||"","main");fe({title:"更新成功",description:`${J.manifest.name} 已从 ${Z.old_version} 更新到 ${Z.new_version}`});const Le=await Il();O(Le),b(le=>le.map(De=>{if(De.id===J.id){const xe=bn(De.id,Le),Me=yn(De.id,Le);return{...De,installed:xe,installed_version:Me}}return De}))}catch(Z){fe({title:"更新失败",description:Z instanceof Error?Z.message:"未知错误",variant:"destructive"})}};return e.jsx(ts,{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:()=>l(),disabled:r,children:[e.jsx(hv,{className:`h-4 w-4 mr-2 ${r?"animate-spin":""}`}),"重启麦麦"]}),e.jsxs(_,{onClick:()=>a({to:"/plugin-mirrors"}),children:[e.jsx(K1,{className:"h-4 w-4 mr-2"}),"配置镜像源"]})]})]}),e.jsx(Te,{className:"border-blue-200 bg-blue-50 dark:bg-blue-950/20 dark:border-blue-900",children:e.jsx(ze,{className:"py-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Yt,{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(Te,{className:"border-orange-600 bg-orange-50 dark:bg-orange-950/20",children:[e.jsx(Oe,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Lt,{className:"h-5 w-5 text-orange-600"}),e.jsxs("div",{children:[e.jsx(Ue,{className:"text-lg text-orange-900 dark:text-orange-100",children:"Git 未安装"}),e.jsx(Ns,{className:"text-orange-800 dark:text-orange-200",children:S.error||"请先安装 Git 才能使用插件安装功能"})]})]})}),e.jsx(ze,{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(Te,{className:"p-4",children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row gap-4",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx($t,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ne,{placeholder:"搜索插件...",value:c,onChange:J=>d(J.target.value),className:"pl-9"})]}),e.jsxs(Pe,{value:m,onValueChange:h,children:[e.jsx(Be,{className:"w-full sm:w-[200px]",children:e.jsx(Fe,{placeholder:"选择分类"})}),e.jsxs(Ie,{children:[e.jsx(W,{value:"all",children:"全部分类"}),e.jsx(W,{value:"Group Management",children:"群组管理"}),e.jsx(W,{value:"Entertainment & Interaction",children:"娱乐互动"}),e.jsx(W,{value:"Utility Tools",children:"实用工具"}),e.jsx(W,{value:"Content Generation",children:"内容生成"}),e.jsx(W,{value:"Multimedia",children:"多媒体"}),e.jsx(W,{value:"External Integration",children:"外部集成"}),e.jsx(W,{value:"Data Analysis & Insights",children:"数据分析与洞察"}),e.jsx(W,{value:"Other",children:"其他"})]})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(tt,{id:"compatible-only",checked:g,onCheckedChange:J=>N(J===!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(Jt,{value:f,onValueChange:p,className:"w-full",children:e.jsxs(Gt,{className:"grid w-full grid-cols-3",children:[e.jsxs(Xe,{value:"all",children:["全部插件 (",j.filter(J=>{if(!J.manifest)return!1;const Z=c===""||J.manifest.name?.toLowerCase().includes(c.toLowerCase())||J.manifest.description?.toLowerCase().includes(c.toLowerCase())||J.manifest.keywords&&J.manifest.keywords.some(De=>De.toLowerCase().includes(c.toLowerCase())),Le=m==="all"||J.manifest.categories&&J.manifest.categories.includes(m),le=!g||!R||$(J);return Z&&Le&&le}).length,")"]}),e.jsxs(Xe,{value:"installed",children:["已安装 (",j.filter(J=>{if(!J.manifest)return!1;const Z=c===""||J.manifest.name?.toLowerCase().includes(c.toLowerCase())||J.manifest.description?.toLowerCase().includes(c.toLowerCase())||J.manifest.keywords&&J.manifest.keywords.some(De=>De.toLowerCase().includes(c.toLowerCase())),Le=m==="all"||J.manifest.categories&&J.manifest.categories.includes(m),le=!g||!R||$(J);return J.installed&&Z&&Le&&le}).length,")"]}),e.jsxs(Xe,{value:"updates",children:["可更新 (",j.filter(J=>{if(!J.manifest)return!1;const Z=c===""||J.manifest.name?.toLowerCase().includes(c.toLowerCase())||J.manifest.description?.toLowerCase().includes(c.toLowerCase())||J.manifest.keywords&&J.manifest.keywords.some(De=>De.toLowerCase().includes(c.toLowerCase())),Le=m==="all"||J.manifest.categories&&J.manifest.categories.includes(m),le=!g||!R||$(J);return J.installed&&A(J)&&Z&&Le&&le}).length,")"]})]})}),E&&E.stage==="loading"&&E.operation==="fetch"&&e.jsx(Te,{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(Fs,{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(tr,{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(Te,{className:"border-destructive bg-destructive/10",children:e.jsx(Oe,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Lt,{className:"h-5 w-5 text-destructive"}),e.jsxs("div",{children:[e.jsx(Ue,{className:"text-lg text-destructive",children:"加载失败"}),e.jsx(Ns,{className:"text-destructive/80",children:E.error})]})]})})}),y?e.jsxs("div",{className:"flex items-center justify-center py-12",children:[e.jsx(Fs,{className:"h-8 w-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"加载插件列表中..."})]}):z?e.jsx(Te,{className:"p-6",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx(Lt,{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:z}),e.jsx(_,{onClick:()=>window.location.reload(),children:"重新加载"})]})}):K.length===0?e.jsx(Te,{className:"p-6",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx($t,{className:"h-12 w-12 text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"未找到插件"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:c||m!=="all"?"尝试调整搜索条件或筛选器":"暂无可用插件"})]})}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:K.map(J=>e.jsxs(Te,{className:"flex flex-col hover:shadow-lg transition-shadow h-full",children:[e.jsxs(Oe,{children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx(Ue,{className:"text-xl",children:J.manifest?.name||J.id}),e.jsxs("div",{className:"flex flex-col gap-1",children:[J.manifest?.categories&&J.manifest.categories[0]&&e.jsx(Ce,{variant:"secondary",className:"text-xs whitespace-nowrap",children:vC[J.manifest.categories[0]]||J.manifest.categories[0]}),G(J)]})]}),e.jsx(Ns,{className:"line-clamp-2",children:J.manifest?.description||"无描述"})]}),e.jsx(ze,{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(na,{className:"h-4 w-4"}),e.jsx("span",{children:(X[J.id]?.downloads??J.downloads??0).toLocaleString()})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(vn,{className:"h-4 w-4 fill-yellow-400 text-yellow-400"}),e.jsx("span",{children:(X[J.id]?.rating??J.rating??0).toFixed(1)})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[J.manifest?.keywords&&J.manifest.keywords.slice(0,3).map(Z=>e.jsx(Ce,{variant:"outline",className:"text-xs",children:Z},Z)),J.manifest?.keywords&&J.manifest.keywords.length>3&&e.jsxs(Ce,{variant:"outline",className:"text-xs",children:["+",J.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",J.manifest?.version||"unknown"," · ",J.manifest?.author?.name||"Unknown"]}),J.manifest?.host_application&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{children:"支持:"}),e.jsxs("span",{className:"font-medium",children:[J.manifest.host_application.min_version,J.manifest.host_application.max_version?` - ${J.manifest.host_application.max_version}`:" - 最新版本"]})]})]})]})}),e.jsx(od,{className:"pt-4",children:e.jsxs("div",{className:"flex items-center justify-end gap-2 w-full",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>a({to:"/plugin-detail",search:{pluginId:J.id}}),children:"查看详情"}),J.installed?A(J)?e.jsxs(_,{size:"sm",disabled:!S?.installed,title:S?.installed?void 0:"Git 未安装",onClick:()=>cs(J),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:()=>$e(J),children:[e.jsx(os,{className:"h-4 w-4 mr-1"}),"卸载"]}):e.jsxs(_,{size:"sm",disabled:!S?.installed||E?.operation==="install"||R!==null&&!$(J),title:S?.installed?R!==null&&!$(J)?`不兼容当前版本 (需要 ${J.manifest?.host_application?.min_version||"未知"}${J.manifest?.host_application?.max_version?` - ${J.manifest.host_application.max_version}`:"+"},当前 ${R?.version})`:void 0:"Git 未安装",onClick:()=>Re(J),children:[e.jsx(na,{className:"h-4 w-4 mr-1"}),E?.operation==="install"&&E?.plugin_id===J.id?"安装中...":"安装"]})]})}),E&&(E.stage==="loading"||E.stage==="success"||E.stage==="error")&&E.operation!=="fetch"&&E.plugin_id===J.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(Fs,{className:"h-3 w-3 animate-spin"}):E.stage==="success"?e.jsx(st,{className:"h-3 w-3 text-green-600"}):e.jsx(Ut,{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(tr,{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})]})})]},J.id))}),e.jsx(Qs,{open:me,onOpenChange:Ne,children:e.jsxs(Hs,{children:[e.jsxs(qs,{children:[e.jsx(Vs,{children:"安装插件"}),e.jsxs(at,{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(tt,{id:"advanced-options",checked:Y,onCheckedChange:J=>we(J)}),e.jsx("label",{htmlFor:"advanced-options",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"高级选项"})]}),Y&&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(Jt,{value:B,onValueChange:J=>ue(J),children:[e.jsxs(Gt,{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:"自定义分支"})]}),B==="preset"&&e.jsx("div",{className:"mt-3",children:e.jsxs(Pe,{value:ge,onValueChange:pe,children:[e.jsx(Be,{children:e.jsx(Fe,{placeholder:"选择分支"})}),e.jsxs(Ie,{children:[e.jsx(W,{value:"main",children:"main (默认)"}),e.jsx(W,{value:"master",children:"master"}),e.jsx(W,{value:"dev",children:"dev (开发版)"}),e.jsx(W,{value:"develop",children:"develop"}),e.jsx(W,{value:"beta",children:"beta (测试版)"}),e.jsx(W,{value:"stable",children:"stable (稳定版)"})]})]})}),B==="custom"&&e.jsxs("div",{className:"space-y-2 mt-3",children:[e.jsx("input",{type:"text",className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",placeholder:"输入分支名称,例如: feature/new-feature",value:D,onChange:J=>Q(J.target.value)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"输入 Git 分支名称、标签或提交哈希"})]})]})]})}),!Y&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"将从默认分支 (main) 安装插件"})]}),e.jsxs(gt,{children:[e.jsx(_,{variant:"outline",onClick:()=>Ne(!1),children:"取消"}),e.jsxs(_,{onClick:se,children:[e.jsx(na,{className:"h-4 w-4 mr-2"}),"安装"]})]})]})}),e.jsx(nr,{})]})})}function yC(){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(fv,{className:"h-8 w-8",strokeWidth:2}),"模型分配预设市场"]}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm sm:text-base",children:"浏览和下载社区共享的模型分配预设配置"})]})})}),e.jsx(ts,{className:"flex-1",children:e.jsx("div",{className:"flex items-center justify-center h-[calc(100vh-12rem)]",children:e.jsxs(Te,{className:"max-w-2xl w-full border-dashed",children:[e.jsxs(Oe,{className:"text-center",children:[e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx(xa,{className:"h-16 w-16 text-muted-foreground"})}),e.jsx(Ue,{className:"text-2xl",children:"功能开发中"}),e.jsx(Ns,{className:"text-base",children:"模型分配预设市场功能正在开发中,敬请期待!"})]}),e.jsx(ze,{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 wC({field:a,value:l,onChange:r}){const[c,d]=u.useState(!1);switch(a.ui_type){case"switch":return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(T,{children:a.label}),a.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.hint})]}),e.jsx(Ge,{checked:!!l,onCheckedChange:r,disabled:a.disabled})]});case"number":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:a.label}),e.jsx(ne,{type:"number",value:l??a.default,onChange:m=>r(parseFloat(m.target.value)||0),min:a.min,max:a.max,step:a.step??1,placeholder:a.placeholder,disabled:a.disabled}),a.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.hint})]});case"slider":return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{children:a.label}),e.jsx("span",{className:"text-sm text-muted-foreground",children:l??a.default})]}),e.jsx(el,{value:[l??a.default],onValueChange:m=>r(m[0]),min:a.min??0,max:a.max??100,step:a.step??1,disabled:a.disabled}),a.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.hint})]});case"select":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:a.label}),e.jsxs(Pe,{value:String(l??a.default),onValueChange:r,disabled:a.disabled,children:[e.jsx(Be,{children:e.jsx(Fe,{placeholder:a.placeholder??"请选择"})}),e.jsx(Ie,{children:a.choices?.map(m=>e.jsx(W,{value:String(m),children:String(m)},String(m)))})]}),a.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.hint})]});case"textarea":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:a.label}),e.jsx(pt,{value:l??a.default,onChange:m=>r(m.target.value),placeholder:a.placeholder,rows:a.rows??3,disabled:a.disabled}),a.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.hint})]});case"password":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:a.label}),e.jsxs("div",{className:"relative",children:[e.jsx(ne,{type:c?"text":"password",value:l??"",onChange:m=>r(m.target.value),placeholder:a.placeholder,disabled:a.disabled,className:"pr-10"}),e.jsx(_,{type:"button",variant:"ghost",size:"icon",className:"absolute right-0 top-0 h-full px-3",onClick:()=>d(!c),children:c?e.jsx(ic,{className:"h-4 w-4"}):e.jsx(ua,{className:"h-4 w-4"})})]}),a.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.hint})]});case"list":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:a.label}),e.jsx(TS,{value:Array.isArray(l)?l:[],onChange:m=>r(m),itemType:a.item_type??"string",itemFields:a.item_fields,minItems:a.min_items,maxItems:a.max_items,disabled:a.disabled,placeholder:a.placeholder}),a.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.hint})]});case"text":default:return e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:a.label}),e.jsx(ne,{type:"text",value:l??a.default??"",onChange:m=>r(m.target.value),placeholder:a.placeholder,maxLength:a.max_length,disabled:a.disabled}),a.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.hint})]})}}function lj({section:a,config:l,onChange:r}){const[c,d]=u.useState(!a.collapsed),m=Object.entries(a.fields).filter(([,h])=>!h.hidden).sort(([,h],[,f])=>h.order-f.order);return e.jsx(xc,{open:c,onOpenChange:d,children:e.jsxs(Te,{children:[e.jsx(hc,{asChild:!0,children:e.jsxs(Oe,{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(Ba,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(ra,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(Ue,{className:"text-lg",children:a.title})]}),e.jsxs(Ce,{variant:"secondary",className:"text-xs",children:[m.length," 项"]})]}),a.description&&e.jsx(Ns,{className:"ml-6",children:a.description})]})}),e.jsx(fc,{children:e.jsx(ze,{className:"space-y-4 pt-0",children:m.map(([h,f])=>e.jsx(wC,{field:f,value:l[a.name]?.[h],onChange:p=>r(a.name,h,p),sectionName:a.name},h))})})]})})}function _C({plugin:a,onBack:l}){const{toast:r}=nt(),{triggerRestart:c,isRestarting:d}=Tn(),[m,h]=u.useState("visual"),[f,p]=u.useState(null),[g,N]=u.useState({}),[j,b]=u.useState({}),[y,w]=u.useState(""),[z,M]=u.useState(""),[S,F]=u.useState(!0),[E,C]=u.useState(!1),[R,H]=u.useState(!1),[O,X]=u.useState(!1),[L,me]=u.useState(!1),Ne=u.useCallback(async()=>{F(!0);try{const[B,ue,Y]=await Promise.all([cC(a.id),oC(a.id),dC(a.id)]);p(B),N(ue),b(JSON.parse(JSON.stringify(ue))),w(Y),M(Y)}catch(B){r({title:"加载配置失败",description:B instanceof Error?B.message:"未知错误",variant:"destructive"})}finally{F(!1)}},[a.id,r]);u.useEffect(()=>{Ne()},[Ne]),u.useEffect(()=>{H(m==="visual"?JSON.stringify(g)!==JSON.stringify(j):y!==z)},[g,j,y,z,m]);const je=(B,ue,Y)=>{N(we=>({...we,[B]:{...we[B]||{},[ue]:Y}}))},ce=async()=>{C(!0);try{if(m==="source"){try{_x(y)}catch(B){X(!0),r({title:"TOML 格式错误",description:B instanceof Error?B.message:"无法解析 TOML 配置,请检查语法",variant:"destructive"}),C(!1);return}await mC(a.id,y),M(y),X(!1)}else await uC(a.id,g),b(JSON.parse(JSON.stringify(g)));r({title:"配置已保存",description:"更改将在插件重新加载后生效"})}catch(B){r({title:"保存失败",description:B instanceof Error?B.message:"未知错误",variant:"destructive"})}finally{C(!1)}},ge=async()=>{try{await xC(a.id),r({title:"配置已重置",description:"下次加载插件时将使用默认配置"}),me(!1),Ne()}catch(B){r({title:"重置失败",description:B instanceof Error?B.message:"未知错误",variant:"destructive"})}},pe=async()=>{try{const B=await hC(a.id);r({title:B.message,description:B.note}),Ne()}catch(B){r({title:"切换状态失败",description:B instanceof Error?B.message:"未知错误",variant:"destructive"})}};if(S)return e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(Fs,{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(Ut,{className:"h-12 w-12 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground",children:"无法加载配置"}),e.jsxs(_,{onClick:l,variant:"outline",children:[e.jsx($a,{className:"h-4 w-4 mr-2"}),"返回"]})]});const D=Object.values(f.sections).sort((B,ue)=>B.order-ue.order),Q=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:l,children:e.jsx($a,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:f.plugin_info.name||a.manifest.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx(Ce,{variant:Q?"default":"secondary",children:Q?"已启用":"已禁用"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["v",f.plugin_info.version||a.manifest.version]})]})]})]}),e.jsxs("div",{className:"flex gap-2 ml-10 sm:ml-0",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>h(m==="visual"?"source":"visual"),children:m==="visual"?e.jsxs(e.Fragment,{children:[e.jsx(dx,{className:"h-4 w-4 mr-2"}),"源代码"]}):e.jsxs(e.Fragment,{children:[e.jsx(uv,{className:"h-4 w-4 mr-2"}),"可视化"]})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>c(),disabled:d,children:[e.jsx(hv,{className:`h-4 w-4 mr-2 ${d?"animate-spin":""}`}),"重启麦麦"]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:pe,children:[e.jsx(pc,{className:"h-4 w-4 mr-2"}),Q?"禁用":"启用"]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>me(!0),children:[e.jsx(rc,{className:"h-4 w-4 mr-2"}),"重置"]}),e.jsxs(_,{size:"sm",onClick:ce,disabled:!R||E,children:[E?e.jsx(Fs,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(gc,{className:"h-4 w-4 mr-2"}),"保存"]})]})]}),R&&e.jsx(Te,{className:"border-orange-200 bg-orange-50 dark:bg-orange-950/20 dark:border-orange-900",children:e.jsx(ze,{className:"py-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Yt,{className:"h-4 w-4 text-orange-600"}),e.jsx("p",{className:"text-sm text-orange-800 dark:text-orange-200",children:"有未保存的更改"})]})})}),m==="source"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(ht,{children:[e.jsx(Ut,{className:"h-4 w-4"}),e.jsxs(ft,{children:[e.jsx("strong",{children:"源代码模式(高级功能):"}),"直接编辑 TOML 配置文件。保存时会验证格式,只有格式正确才能保存。",O&&e.jsx("span",{className:"text-destructive font-semibold ml-2",children:"⚠️ 上次保存失败,请检查 TOML 格式"})]})]}),e.jsx(Qv,{value:y,onChange:B=>{w(B),O&&X(!1)},language:"toml",theme:"dark",height:"calc(100vh - 350px)",minHeight:"500px",placeholder:"TOML 配置内容"})]}),m==="visual"&&e.jsxs(e.Fragment,{children:[e.jsxs(ht,{children:[e.jsx(Yt,{className:"h-4 w-4"}),e.jsxs(ft,{children:[e.jsx("strong",{children:"提示:"}),"如果插件当前未加载或未启用,WebUI 适配器的高级插件可视化编辑功能可能会不可用。 请确保插件已启用并成功加载后,再进行配置编辑。"]})]}),f.layout.type==="tabs"&&f.layout.tabs.length>0?e.jsxs(Jt,{defaultValue:f.layout.tabs[0]?.id,children:[e.jsx(Gt,{children:f.layout.tabs.map(B=>e.jsxs(Xe,{value:B.id,children:[B.title,B.badge&&e.jsx(Ce,{variant:"secondary",className:"ml-2 text-xs",children:B.badge})]},B.id))}),f.layout.tabs.map(B=>e.jsx(Ss,{value:B.id,className:"space-y-4 mt-4",children:B.sections.map(ue=>{const Y=f.sections[ue];return Y?e.jsx(lj,{section:Y,config:g,onChange:je},ue):null})},B.id))]}):e.jsx("div",{className:"space-y-4",children:D.map(B=>e.jsx(lj,{section:B,config:g,onChange:je},B.name))})]}),e.jsx(Qs,{open:L,onOpenChange:me,children:e.jsxs(Hs,{children:[e.jsxs(qs,{children:[e.jsx(Vs,{children:"确认重置配置"}),e.jsx(at,{children:"这将删除当前配置文件,下次加载插件时将使用默认配置。此操作不可撤销。"})]}),e.jsxs(gt,{children:[e.jsx(_,{variant:"outline",onClick:()=>me(!1),children:"取消"}),e.jsx(_,{variant:"destructive",onClick:ge,children:"确认重置"})]})]})})]})}function SC(){return e.jsx(lr,{children:e.jsx(kC,{})})}function kC(){const{toast:a}=nt(),[l,r]=u.useState([]),[c,d]=u.useState(!0),[m,h]=u.useState(""),[f,p]=u.useState(null),g=async()=>{d(!0);try{const w=await Il();r(w)}catch(w){a({title:"加载插件列表失败",description:w instanceof Error?w.message:"未知错误",variant:"destructive"})}finally{d(!1)}};u.useEffect(()=>{g()},[]);const j=l.filter(w=>{const z=m.toLowerCase();return w.id.toLowerCase().includes(z)||w.manifest.name.toLowerCase().includes(z)||w.manifest.description?.toLowerCase().includes(z)}).filter((w,z,M)=>z===M.findIndex(S=>S.id===w.id)),b=l.length,y=0;return f?e.jsxs(e.Fragment,{children:[e.jsx(ts,{className:"h-full",children:e.jsx("div",{className:"p-4 sm:p-6",children:e.jsx(_C,{plugin:f,onBack:()=>p(null)})})}),e.jsx(nr,{})]}):e.jsx(ts,{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(Te,{children:[e.jsxs(Oe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Ue,{className:"text-sm font-medium",children:"已安装插件"}),e.jsx(xa,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(ze,{children:[e.jsx("div",{className:"text-2xl font-bold",children:l.length}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:c?"正在加载...":"个插件"})]})]}),e.jsxs(Te,{children:[e.jsxs(Oe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Ue,{className:"text-sm font-medium",children:"已启用"}),e.jsx(st,{className:"h-4 w-4 text-green-600"})]}),e.jsxs(ze,{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(Te,{children:[e.jsxs(Oe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Ue,{className:"text-sm font-medium",children:"已禁用"}),e.jsx(Ut,{className:"h-4 w-4 text-orange-600"})]}),e.jsxs(ze,{children:[e.jsx("div",{className:"text-2xl font-bold",children:y}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"未激活的插件"})]})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx($t,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ne,{placeholder:"搜索插件...",value:m,onChange:w=>h(w.target.value),className:"pl-9"})]}),e.jsxs(Te,{children:[e.jsxs(Oe,{children:[e.jsx(Ue,{children:"已安装的插件"}),e.jsx(Ns,{children:"点击插件查看和编辑配置"})]}),e.jsx(ze,{children:c?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(Fs,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):j.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 space-y-4",children:[e.jsx(xa,{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:m?"没有找到匹配的插件":"暂无已安装的插件"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:m?"尝试其他搜索关键词":"前往插件市场安装插件"})]})]}):e.jsx("div",{className:"space-y-2",children:j.map(w=>e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg border hover:bg-muted/50 cursor-pointer transition-colors",onClick:()=>p(w),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(xa,{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:w.manifest.name}),e.jsxs(Ce,{variant:"secondary",className:"text-xs flex-shrink-0",children:["v",w.manifest.version]})]}),e.jsx("p",{className:"text-sm text-muted-foreground truncate",children:w.manifest.description||"暂无描述"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx(_,{variant:"ghost",size:"sm",children:e.jsx(Sn,{className:"h-4 w-4"})}),e.jsx(ra,{className:"h-4 w-4 text-muted-foreground"})]})]},w.id))})})]})]})})}function CC(){const a=ha(),{toast:l}=nt(),[r,c]=u.useState([]),[d,m]=u.useState(!0),[h,f]=u.useState(null),[p,g]=u.useState(null),[N,j]=u.useState(!1),[b,y]=u.useState(!1),[w,z]=u.useState({id:"",name:"",raw_prefix:"",clone_prefix:"",enabled:!0,priority:1}),M=u.useCallback(async()=>{try{m(!0),f(null);const O=await ke("/api/webui/plugins/mirrors");if(!O.ok)throw new Error("获取镜像源列表失败");const X=await O.json();c(X.mirrors||[])}catch(O){const X=O instanceof Error?O.message:"加载镜像源失败";f(X),l({title:"加载失败",description:X,variant:"destructive"})}finally{m(!1)}},[l]);u.useEffect(()=>{M()},[M]);const S=async()=>{try{const O=await ke("/api/webui/plugins/mirrors",{method:"POST",body:JSON.stringify(w)});if(!O.ok){const X=await O.json();throw new Error(X.detail||"添加镜像源失败")}l({title:"添加成功",description:"镜像源已添加"}),j(!1),z({id:"",name:"",raw_prefix:"",clone_prefix:"",enabled:!0,priority:1}),M()}catch(O){l({title:"添加失败",description:O instanceof Error?O.message:"未知错误",variant:"destructive"})}},F=async()=>{if(p)try{if(!(await ke(`/api/webui/plugins/mirrors/${p.id}`,{method:"PUT",body:JSON.stringify({name:w.name,raw_prefix:w.raw_prefix,clone_prefix:w.clone_prefix,enabled:w.enabled,priority:w.priority})})).ok)throw new Error("更新镜像源失败");l({title:"更新成功",description:"镜像源已更新"}),y(!1),g(null),M()}catch(O){l({title:"更新失败",description:O instanceof Error?O.message:"未知错误",variant:"destructive"})}},E=async O=>{if(confirm("确定要删除这个镜像源吗?"))try{if(!(await ke(`/api/webui/plugins/mirrors/${O}`,{method:"DELETE"})).ok)throw new Error("删除镜像源失败");l({title:"删除成功",description:"镜像源已删除"}),M()}catch(X){l({title:"删除失败",description:X instanceof Error?X.message:"未知错误",variant:"destructive"})}},C=async O=>{try{if(!(await ke(`/api/webui/plugins/mirrors/${O.id}`,{method:"PUT",body:JSON.stringify({enabled:!O.enabled})})).ok)throw new Error("更新状态失败");M()}catch(X){l({title:"更新失败",description:X instanceof Error?X.message:"未知错误",variant:"destructive"})}},R=O=>{g(O),z({id:O.id,name:O.name,raw_prefix:O.raw_prefix,clone_prefix:O.clone_prefix,enabled:O.enabled,priority:O.priority}),y(!0)},H=async(O,X)=>{const L=X==="up"?O.priority-1:O.priority+1;if(!(L<1))try{if(!(await ke(`/api/webui/plugins/mirrors/${O.id}`,{method:"PUT",body:JSON.stringify({priority:L})})).ok)throw new Error("更新优先级失败");M()}catch(me){l({title:"更新失败",description:me instanceof Error?me.message:"未知错误",variant:"destructive"})}};return e.jsx(ts,{className:"h-full",children:e.jsxs("div",{className:"space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(_,{variant:"ghost",size:"icon",onClick:()=>a({to:"/plugins"}),children:e.jsx($a,{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:()=>j(!0),children:[e.jsx(Xs,{className:"h-4 w-4 mr-2"}),"添加镜像源"]})]}),d?e.jsx(Te,{className:"p-6",children:e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(Fs,{className:"h-8 w-8 animate-spin text-primary"})})}):h?e.jsx(Te,{className:"p-6",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx(Lt,{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:M,children:"重新加载"})]})}):e.jsxs(Te,{children:[e.jsx("div",{className:"hidden md:block",children:e.jsxs(ql,{children:[e.jsx(Vl,{children:e.jsxs(_t,{children:[e.jsx(ns,{children:"状态"}),e.jsx(ns,{children:"名称"}),e.jsx(ns,{children:"ID"}),e.jsx(ns,{children:"优先级"}),e.jsx(ns,{className:"text-right",children:"操作"})]})}),e.jsx(Gl,{children:r.map(O=>e.jsxs(_t,{children:[e.jsx(Ze,{children:e.jsx(Ge,{checked:O.enabled,onCheckedChange:()=>C(O)})}),e.jsx(Ze,{children:e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:O.name}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:["Raw: ",O.raw_prefix]})]})}),e.jsx(Ze,{children:e.jsx(Ce,{variant:"outline",children:O.id})}),e.jsx(Ze,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-mono",children:O.priority}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(_,{variant:"ghost",size:"icon",className:"h-5 w-5",onClick:()=>H(O,"up"),disabled:O.priority===1,children:e.jsx(Xr,{className:"h-3 w-3"})}),e.jsx(_,{variant:"ghost",size:"icon",className:"h-5 w-5",onClick:()=>H(O,"down"),children:e.jsx(Ba,{className:"h-3 w-3"})})]})]})}),e.jsx(Ze,{className:"text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(_,{variant:"ghost",size:"icon",onClick:()=>R(O),children:e.jsx(Zn,{className:"h-4 w-4"})}),e.jsx(_,{variant:"ghost",size:"icon",onClick:()=>E(O.id),children:e.jsx(os,{className:"h-4 w-4 text-destructive"})})]})})]},O.id))})]})}),e.jsx("div",{className:"md:hidden p-4 space-y-4",children:r.map(O=>e.jsx(Te,{className:"p-4",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"font-semibold",children:O.name}),O.enabled&&e.jsx(Ce,{variant:"default",className:"text-xs",children:"启用"})]}),e.jsx(Ce,{variant:"outline",className:"mt-1 text-xs",children:O.id})]}),e.jsx(Ge,{checked:O.enabled,onCheckedChange:()=>C(O)})]}),e.jsxs("div",{className:"text-sm space-y-1",children:[e.jsxs("div",{className:"text-muted-foreground",children:[e.jsx("span",{className:"font-medium",children:"Raw: "}),e.jsx("span",{className:"break-all",children:O.raw_prefix})]}),e.jsxs("div",{className:"text-muted-foreground",children:[e.jsx("span",{className:"font-medium",children:"优先级: "}),e.jsx("span",{className:"font-mono",children:O.priority})]})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-2 border-t",children:[e.jsxs(_,{variant:"outline",size:"sm",className:"flex-1",onClick:()=>R(O),children:[e.jsx(Zn,{className:"h-4 w-4 mr-1"}),"编辑"]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>H(O,"up"),disabled:O.priority===1,children:e.jsx(Xr,{className:"h-4 w-4"})}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>H(O,"down"),children:e.jsx(Ba,{className:"h-4 w-4"})}),e.jsx(_,{variant:"destructive",size:"sm",onClick:()=>E(O.id),children:e.jsx(os,{className:"h-4 w-4"})})]})]})},O.id))})]}),e.jsx(Qs,{open:N,onOpenChange:j,children:e.jsxs(Hs,{className:"max-w-lg",children:[e.jsxs(qs,{children:[e.jsx(Vs,{children:"添加镜像源"}),e.jsx(at,{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(ne,{id:"add-id",placeholder:"例如: my-mirror",value:w.id,onChange:O=>z({...w,id:O.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"add-name",children:"名称 *"}),e.jsx(ne,{id:"add-name",placeholder:"例如: 我的镜像源",value:w.name,onChange:O=>z({...w,name:O.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"add-raw",children:"Raw 文件前缀 *"}),e.jsx(ne,{id:"add-raw",placeholder:"https://example.com/raw",value:w.raw_prefix,onChange:O=>z({...w,raw_prefix:O.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"add-clone",children:"克隆前缀 *"}),e.jsx(ne,{id:"add-clone",placeholder:"https://example.com/clone",value:w.clone_prefix,onChange:O=>z({...w,clone_prefix:O.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"add-priority",children:"优先级"}),e.jsx(ne,{id:"add-priority",type:"number",min:"1",value:w.priority,onChange:O=>z({...w,priority:parseInt(O.target.value)||1})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"数字越小优先级越高"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ge,{id:"add-enabled",checked:w.enabled,onCheckedChange:O=>z({...w,enabled:O})}),e.jsx(T,{htmlFor:"add-enabled",children:"启用此镜像源"})]})]}),e.jsxs(gt,{children:[e.jsx(_,{variant:"outline",onClick:()=>j(!1),children:"取消"}),e.jsx(_,{onClick:S,children:"添加"})]})]})}),e.jsx(Qs,{open:b,onOpenChange:y,children:e.jsxs(Hs,{className:"max-w-lg",children:[e.jsxs(qs,{children:[e.jsx(Vs,{children:"编辑镜像源"}),e.jsx(at,{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(ne,{value:w.id,disabled:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"edit-name",children:"名称 *"}),e.jsx(ne,{id:"edit-name",value:w.name,onChange:O=>z({...w,name:O.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"edit-raw",children:"Raw 文件前缀 *"}),e.jsx(ne,{id:"edit-raw",value:w.raw_prefix,onChange:O=>z({...w,raw_prefix:O.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"edit-clone",children:"克隆前缀 *"}),e.jsx(ne,{id:"edit-clone",value:w.clone_prefix,onChange:O=>z({...w,clone_prefix:O.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"edit-priority",children:"优先级"}),e.jsx(ne,{id:"edit-priority",type:"number",min:"1",value:w.priority,onChange:O=>z({...w,priority:parseInt(O.target.value)||1})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"数字越小优先级越高"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ge,{id:"edit-enabled",checked:w.enabled,onCheckedChange:O=>z({...w,enabled:O})}),e.jsx(T,{htmlFor:"edit-enabled",children:"启用此镜像源"})]})]}),e.jsxs(gt,{children:[e.jsx(_,{variant:"outline",onClick:()=>y(!1),children:"取消"}),e.jsx(_,{onClick:F,children:"保存"})]})]})})]})})}function TC({pluginId:a,compact:l=!1}){const[r,c]=u.useState(null),[d,m]=u.useState(!0),[h,f]=u.useState(0),[p,g]=u.useState(""),[N,j]=u.useState(!1),{toast:b}=nt(),y=async()=>{m(!0);const S=await bN(a);S&&c(S),m(!1)};u.useEffect(()=>{y()},[a]);const w=async()=>{const S=await fC(a);S.success?(b({title:"已点赞",description:"感谢你的支持!"}),y()):b({title:"点赞失败",description:S.error||"未知错误",variant:"destructive"})},z=async()=>{const S=await pC(a);S.success?(b({title:"已反馈",description:"感谢你的反馈!"}),y()):b({title:"操作失败",description:S.error||"未知错误",variant:"destructive"})},M=async()=>{if(h===0){b({title:"请选择评分",description:"至少选择 1 颗星",variant:"destructive"});return}const S=await gC(a,h,p||void 0);S.success?(b({title:"评分成功",description:"感谢你的评价!"}),j(!1),f(0),g(""),y()):b({title:"评分失败",description:S.error||"未知错误",variant:"destructive"})};return d?e.jsxs("div",{className:"flex items-center gap-4 text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(na,{className:"h-4 w-4"}),e.jsx("span",{children:"-"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(vn,{className:"h-4 w-4"}),e.jsx("span",{children:"-"})]})]}):r?l?e.jsxs("div",{className:"flex items-center gap-4 text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1",title:`下载量: ${r.downloads.toLocaleString()}`,children:[e.jsx(na,{className:"h-4 w-4"}),e.jsx("span",{children:r.downloads.toLocaleString()})]}),e.jsxs("div",{className:"flex items-center gap-1",title:`评分: ${r.rating.toFixed(1)} (${r.rating_count} 条评价)`,children:[e.jsx(vn,{className:"h-4 w-4 fill-yellow-400 text-yellow-400"}),e.jsx("span",{children:r.rating.toFixed(1)})]}),e.jsxs("div",{className:"flex items-center gap-1",title:`点赞数: ${r.likes}`,children:[e.jsx(Mm,{className:"h-4 w-4"}),e.jsx("span",{children:r.likes})]})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(na,{className:"h-5 w-5 text-muted-foreground mb-1"}),e.jsx("span",{className:"text-2xl font-bold",children:r.downloads.toLocaleString()}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"下载量"})]}),e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(vn,{className:"h-5 w-5 text-yellow-400 mb-1 fill-yellow-400"}),e.jsx("span",{className:"text-2xl font-bold",children:r.rating.toFixed(1)}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[r.rating_count," 条评价"]})]}),e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(Mm,{className:"h-5 w-5 text-green-500 mb-1"}),e.jsx("span",{className:"text-2xl font-bold",children:r.likes}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"点赞"})]}),e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(Ag,{className:"h-5 w-5 text-red-500 mb-1"}),e.jsx("span",{className:"text-2xl font-bold",children:r.dislikes}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"点踩"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(_,{variant:"outline",size:"sm",onClick:w,children:[e.jsx(Mm,{className:"h-4 w-4 mr-1"}),"点赞"]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:z,children:[e.jsx(Ag,{className:"h-4 w-4 mr-1"}),"点踩"]}),e.jsxs(Qs,{open:N,onOpenChange:j,children:[e.jsx(dd,{asChild:!0,children:e.jsxs(_,{variant:"default",size:"sm",children:[e.jsx(vn,{className:"h-4 w-4 mr-1"}),"评分"]})}),e.jsxs(Hs,{children:[e.jsxs(qs,{children:[e.jsx(Vs,{children:"为插件评分"}),e.jsx(at,{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(vn,{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(pt,{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(gt,{children:[e.jsx(_,{variant:"outline",onClick:()=>j(!1),children:"取消"}),e.jsx(_,{onClick:M,disabled:h===0,children:"提交评分"})]})]})]})]}),r.recent_ratings&&r.recent_ratings.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-sm font-semibold",children:"最近评价"}),e.jsx("div",{className:"space-y-3",children:r.recent_ratings.map((S,F)=>e.jsxs("div",{className:"p-3 rounded-lg border bg-muted/50",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("div",{className:"flex gap-1",children:[1,2,3,4,5].map(E=>e.jsx(vn,{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})]},F))})]})]}):null}const EC={"Group Management":"群组管理","Entertainment & Interaction":"娱乐互动","Utility Tools":"实用工具","Content Generation":"内容生成",Multimedia:"多媒体","External Integration":"外部集成","Data Analysis & Insights":"数据分析与洞察",Other:"其他"};function MC(){const a=ha(),l=lw({strict:!1}),{toast:r}=nt(),[c,d]=u.useState(null),[m,h]=u.useState(""),[f,p]=u.useState(!0),[g,N]=u.useState(!0),[j,b]=u.useState(null),[y,w]=u.useState(null),[z,M]=u.useState(null),[S,F]=u.useState(!1),[E,C]=u.useState(),[R,H]=u.useState(!1);u.useEffect(()=>{(async()=>{if(!l.pluginId){b("缺少插件 ID"),p(!1);return}try{p(!0),b(null);const ge=await ke("/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(!ge.ok)throw new Error("获取插件列表失败");const pe=await ge.json();if(!pe.success||!pe.data)throw new Error(pe.error||"获取插件列表失败");const Q=JSON.parse(pe.data).find(fe=>fe.id===l.pluginId);if(!Q)throw new Error("未找到该插件");const B={id:Q.id,manifest:Q.manifest,downloads:0,rating:0,review_count:0,installed:!1,published_at:new Date().toISOString(),updated_at:new Date().toISOString()};d(B);const[ue,Y,we]=await Promise.all([fN(),pN(),Il()]);w(ue),M(Y),F(bn(l.pluginId,we)),C(yn(l.pluginId,we))}catch(ge){b(ge instanceof Error?ge.message:"加载失败")}finally{p(!1)}})()},[l.pluginId]),u.useEffect(()=>{(async()=>{if(!c?.manifest?.repository_url){N(!1);return}try{if(N(!0),S&&l.pluginId)try{const Y=await ke(`/api/webui/plugins/local-readme/${l.pluginId}`);if(Y.ok){const we=await Y.json();if(we.success&&we.data){h(we.data),N(!1);return}}}catch(Y){console.log("本地 README 获取失败,尝试远程获取:",Y)}const ge=c.manifest.repository_url.match(/github\.com\/([^/]+)\/([^/\s]+)/);if(!ge){h("无法解析仓库地址");return}const[,pe,D]=ge,Q=D.replace(/\.git$/,""),B=await ke("/api/webui/plugins/fetch-raw",{method:"POST",body:JSON.stringify({owner:pe,repo:Q,branch:"main",file_path:"README.md"})});if(!B.ok)throw new Error("获取 README 失败");const ue=await B.json();ue.success&&ue.data?h(ue.data):h("该插件暂无 README 文档")}catch(ge){console.error("加载 README 失败:",ge),h("加载 README 失败")}finally{N(!1)}})()},[c,S,l.pluginId]);const O=()=>!c||!S||!E?!1:E!==c.manifest.version,X=()=>!c||!z?!0:gN(c.manifest.host_application.min_version,c.manifest.host_application.max_version,z),L=async()=>{if(!(!c||!y?.installed))try{H(!0),await jN(c.id,c.manifest.repository_url||"","main"),yN(c.id).catch(ge=>{console.warn("Failed to record download:",ge)}),r({title:"安装成功",description:`${c.manifest.name} 已成功安装`});const ce=await Il();F(bn(c.id,ce)),C(yn(c.id,ce))}catch(ce){r({title:"安装失败",description:ce instanceof Error?ce.message:"未知错误",variant:"destructive"})}finally{H(!1)}},me=async()=>{if(c)try{H(!0),await vN(c.id),r({title:"卸载成功",description:`${c.manifest.name} 已成功卸载`});const ce=await Il();F(bn(c.id,ce)),C(yn(c.id,ce))}catch(ce){r({title:"卸载失败",description:ce instanceof Error?ce.message:"未知错误",variant:"destructive"})}finally{H(!1)}},Ne=async()=>{if(!(!c||!y?.installed))try{H(!0);const ce=await NN(c.id,c.manifest.repository_url||"","main");r({title:"更新成功",description:`${c.manifest.name} 已从 ${ce.old_version} 更新到 ${ce.new_version}`});const ge=await Il();F(bn(c.id,ge)),C(yn(c.id,ge))}catch(ce){r({title:"更新失败",description:ce instanceof Error?ce.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:()=>a({to:"/plugins"}),children:e.jsx($a,{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(Fs,{className:"h-8 w-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"加载插件信息中..."})]})]});if(j||!c)return e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(_,{variant:"ghost",size:"icon",onClick:()=>a({to:"/plugins"}),children:e.jsx($a,{className:"h-5 w-5"})}),e.jsx("div",{children:e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"插件详情"})})]}),e.jsx(Te,{className:"p-6",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx(Ut,{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:j}),e.jsx(_,{onClick:()=>a({to:"/plugins"}),children:"返回插件列表"})]})})]});const je=X();return e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(_,{variant:"ghost",size:"icon",onClick:()=>a({to:"/plugins"}),className:"shrink-0",children:e.jsx($a,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"插件详情"}),e.jsx("p",{className:"text-muted-foreground mt-1 sm:mt-2 text-sm sm:text-base",children:c.manifest.name})]})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:S?e.jsxs(e.Fragment,{children:[O()?e.jsx(_,{disabled:!y?.installed||R,onClick:Ne,title:y?.installed?void 0:"Git 未安装",children:R?e.jsxs(e.Fragment,{children:[e.jsx(Fs,{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:!y?.installed||R,onClick:me,title:y?.installed?void 0:"Git 未安装",children:R?e.jsxs(e.Fragment,{children:[e.jsx(Fs,{className:"h-4 w-4 mr-2 animate-spin"}),"卸载中..."]}):e.jsxs(e.Fragment,{children:[e.jsx(os,{className:"h-4 w-4 mr-2"}),"卸载"]})})]}):e.jsx(_,{disabled:!y?.installed||!je||R,onClick:L,title:y?.installed?je?void 0:`不兼容当前版本 (需要 ${c.manifest.host_application.min_version}${c.manifest.host_application.max_version?` - ${c.manifest.host_application.max_version}`:"+"},当前 ${z?.version})`:"Git 未安装",children:R?e.jsxs(e.Fragment,{children:[e.jsx(Fs,{className:"h-4 w-4 mr-2 animate-spin"}),"安装中..."]}):e.jsxs(e.Fragment,{children:[e.jsx(na,{className:"h-4 w-4 mr-2"}),"安装"]})})})]}),e.jsx(ts,{className:"h-[calc(100vh-200px)] sm:h-[calc(100vh-220px)]",children:e.jsxs("div",{className:"space-y-6 pr-4",children:[e.jsx(Te,{children:e.jsx(Oe,{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(Ue,{className:"text-2xl",children:c.manifest.name}),e.jsxs(Ce,{variant:"secondary",className:"text-sm",children:["v",c.manifest.version]}),S&&e.jsxs(Ce,{variant:"default",className:"text-sm",children:[e.jsx(st,{className:"h-3 w-3 mr-1"}),"已安装 ",E&&`(v${E})`]}),O()&&e.jsxs(Ce,{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(Ce,{variant:"destructive",className:"text-sm",children:[e.jsx(Ut,{className:"h-3 w-3 mr-1"}),"不兼容"]})]}),e.jsx(Ns,{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(Te,{children:[e.jsx(Oe,{children:e.jsx(Ue,{className:"text-lg",children:"统计信息"})}),e.jsx(ze,{children:e.jsx(TC,{pluginId:c.id})})]}),e.jsxs(Te,{children:[e.jsx(Oe,{children:e.jsx(Ue,{className:"text-lg",children:"基本信息"})}),e.jsx(ze,{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(Fl,{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(Io,{className:"h-3 w-3"})})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(xa,{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(ov,{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(Go,{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(Io,{className:"h-3 w-3"})]})]}),c.manifest.repository_url&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Q1,{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(Io,{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(Yt,{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(Te,{children:[e.jsx(Oe,{children:e.jsx(Ue,{className:"text-lg",children:"分类与标签"})}),e.jsxs(ze,{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(ce=>e.jsx(Ce,{variant:"secondary",children:EC[ce]||ce},ce))})]}),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(ce=>e.jsxs(Ce,{variant:"outline",className:"text-xs",children:[e.jsx(cd,{className:"h-3 w-3 mr-1"}),ce]},ce))})]})]})]})]}),e.jsxs(Te,{className:"lg:col-span-2",children:[e.jsx(Oe,{children:e.jsx(Ue,{className:"text-lg",children:"插件说明"})}),e.jsx(ze,{children:e.jsx(ts,{className:"h-[600px] pr-4",children:g?e.jsxs("div",{className:"flex items-center justify-center py-12",children:[e.jsx(Fs,{className:"h-6 w-6 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-sm text-muted-foreground",children:"加载说明文档中..."})]}):m?e.jsx(bx,{content:m}):e.jsx("div",{className:"text-center text-muted-foreground py-12",children:"暂无说明文档"})})})]})]})]})})]})}const ec=u.forwardRef(({className:a,...l},r)=>e.jsx(Aj,{ref:r,className:P("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",a),...l}));ec.displayName=Aj.displayName;const AC=u.forwardRef(({className:a,...l},r)=>e.jsx(zj,{ref:r,className:P("aspect-square h-full w-full",a),...l}));AC.displayName=zj.displayName;const sc=u.forwardRef(({className:a,...l},r)=>e.jsx(Rj,{ref:r,className:P("flex h-full w-full items-center justify-center rounded-full bg-muted",a),...l}));sc.displayName=Rj.displayName;function zC(){return"webui_"+Math.random().toString(36).substr(2,9)+"_"+Date.now().toString(36)}function RC(){const a="maibot_webui_user_id";let l=localStorage.getItem(a);return l||(l=zC(),localStorage.setItem(a,l)),l}function DC(){return localStorage.getItem("maibot_webui_user_name")||"WebUI用户"}function OC(a){localStorage.setItem("maibot_webui_user_name",a)}const wN="maibot_webui_virtual_tabs";function LC(){try{const a=localStorage.getItem(wN);if(a)return JSON.parse(a)}catch(a){console.error("[Chat] 加载虚拟标签页失败:",a)}return[]}function nj(a){try{localStorage.setItem(wN,JSON.stringify(a))}catch(l){console.error("[Chat] 保存虚拟标签页失败:",l)}}function UC({segment:a}){switch(a.type){case"text":return e.jsx("span",{className:"whitespace-pre-wrap",children:String(a.data)});case"image":case"emoji":return e.jsx("img",{src:String(a.data),alt:a.type==="emoji"?"表情包":"图片",className:P("rounded-lg max-w-full",a.type==="emoji"?"max-h-32":"max-h-64"),loading:"lazy",onError:l=>{const r=l.target;r.style.display="none",r.parentElement?.insertAdjacentHTML("beforeend",`[${a.type==="emoji"?"表情包":"图片"}加载失败]`)}});case"voice":return e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("audio",{controls:!0,src:String(a.data),className:"max-w-[200px] h-8",children:"您的浏览器不支持音频播放"})});case"video":return e.jsx("video",{controls:!0,src:String(a.data),className:"rounded-lg max-w-full max-h-64",children:"您的浏览器不支持视频播放"});case"face":return e.jsxs("span",{className:"text-muted-foreground",children:["[表情:",String(a.data),"]"]});case"music":return e.jsx("span",{className:"text-muted-foreground",children:"[音乐分享]"});case"file":return e.jsxs("span",{className:"text-muted-foreground",children:["[文件: ",String(a.data),"]"]});case"reply":return e.jsx("span",{className:"text-muted-foreground text-xs",children:"[回复消息]"});case"forward":return e.jsx("span",{className:"text-muted-foreground",children:"[转发消息]"});case"unknown":default:return e.jsxs("span",{className:"text-muted-foreground",children:["[",a.original_type||"未知消息","]"]})}}function $C({message:a,isBot:l}){return a.message_type==="rich"&&a.segments&&a.segments.length>0?e.jsx("div",{className:"flex flex-col gap-2",children:a.segments.map((r,c)=>e.jsx(UC,{segment:r},c))}):e.jsx("span",{className:"whitespace-pre-wrap",children:a.content})}function BC(){const a={id:"webui-default",type:"webui",label:"WebUI",messages:[],isConnected:!1,isTyping:!1,sessionInfo:{}},l=()=>{const Ke=LC().map(He=>{const Je=He.virtualConfig;return!Je.groupId&&Je.platform&&Je.userId&&(Je.groupId=`webui_virtual_group_${Je.platform}_${Je.userId}`),{id:He.id,type:"virtual",label:He.label,virtualConfig:Je,messages:[],isConnected:!1,isTyping:!1,sessionInfo:{}}});return[a,...Ke]},[r,c]=u.useState(l),[d,m]=u.useState("webui-default"),h=r.find(V=>V.id===d)||r[0],[f,p]=u.useState(""),[g,N]=u.useState(!1),[j,b]=u.useState(!0),[y,w]=u.useState(DC()),[z,M]=u.useState(!1),[S,F]=u.useState(""),[E,C]=u.useState(!1),[R,H]=u.useState([]),[O,X]=u.useState([]),[L,me]=u.useState(!1),[Ne,je]=u.useState(!1),[ce,ge]=u.useState(""),[pe,D]=u.useState({platform:"",personId:"",userId:"",userName:"",groupName:"",groupId:""}),Q=u.useRef(RC()),B=u.useRef(new Map),ue=u.useRef(null),Y=u.useRef(new Map),we=u.useRef(0),fe=u.useRef(new Map),{toast:Ee}=nt(),G=V=>(we.current+=1,`${V}-${Date.now()}-${we.current}-${Math.random().toString(36).substr(2,9)}`),$=u.useCallback((V,Ke)=>{c(He=>He.map(Je=>Je.id===V?{...Je,...Ke}:Je))},[]),A=u.useCallback((V,Ke)=>{c(He=>He.map(Je=>Je.id===V?{...Je,messages:[...Je.messages,Ke]}:Je))},[]),K=u.useCallback(()=>{ue.current?.scrollIntoView({behavior:"smooth"})},[]);u.useEffect(()=>{K()},[h?.messages,K]);const Re=u.useCallback(async()=>{me(!0);try{const V=await ke("/api/chat/platforms");if(console.log("[Chat] 平台列表响应:",V.status,V.headers.get("content-type")),V.ok){const Ke=V.headers.get("content-type");if(Ke&&Ke.includes("application/json")){const He=await V.json();console.log("[Chat] 平台列表数据:",He),H(He.platforms||[])}else{const He=await V.text();console.error("[Chat] 获取平台列表失败: 非 JSON 响应:",He.substring(0,200)),Ee({title:"连接失败",description:"无法连接到后端服务,请确保 MaiBot 已启动",variant:"destructive"})}}else console.error("[Chat] 获取平台列表失败: HTTP",V.status),Ee({title:"获取平台失败",description:`服务器返回错误: ${V.status}`,variant:"destructive"})}catch(V){console.error("[Chat] 获取平台列表失败:",V),Ee({title:"网络错误",description:"无法连接到后端服务",variant:"destructive"})}finally{me(!1)}},[Ee]),se=u.useCallback(async(V,Ke)=>{je(!0);try{const He=new URLSearchParams;V&&He.append("platform",V),Ke&&He.append("search",Ke),He.append("limit","50");const Je=await ke(`/api/chat/persons?${He.toString()}`);if(Je.ok){const Es=Je.headers.get("content-type");if(Es&&Es.includes("application/json")){const ms=await Je.json();X(ms.persons||[])}else console.error("[Chat] 获取用户列表失败: 后端返回非 JSON 响应")}}catch(He){console.error("[Chat] 获取用户列表失败:",He)}finally{je(!1)}},[]);u.useEffect(()=>{pe.platform&&se(pe.platform,ce)},[pe.platform,ce,se]);const $e=u.useCallback(async(V,Ke)=>{b(!0);try{const He=new URLSearchParams;He.append("user_id",Q.current),He.append("limit","50"),Ke&&He.append("group_id",Ke);const Je=`/api/chat/history?${He.toString()}`;console.log("[Chat] 正在加载历史消息:",Je);const Es=await ke(Je);if(Es.ok){const ms=await Es.text();try{const Ms=JSON.parse(ms);if(Ms.messages&&Ms.messages.length>0){const We=Ms.messages.map(rs=>({id:rs.id,type:rs.type,content:rs.content,timestamp:rs.timestamp,sender:{name:rs.sender_name||(rs.is_bot?"麦麦":"WebUI用户"),user_id:rs.user_id,is_bot:rs.is_bot}}));$(V,{messages:We});const Cs=fe.current.get(V)||new Set;We.forEach(rs=>{if(rs.type==="bot"){const is=`bot-${rs.content}-${Math.floor(rs.timestamp*1e3)}`;Cs.add(is)}}),fe.current.set(V,Cs)}}catch(Ms){console.error("[Chat] JSON 解析失败:",Ms)}}}catch(He){console.error("[Chat] 加载历史消息失败:",He)}finally{b(!1)}},[$]),cs=u.useCallback(async(V,Ke,He)=>{const Je=B.current.get(V);if(Je?.readyState===WebSocket.OPEN||Je?.readyState===WebSocket.CONNECTING){console.log(`[Tab ${V}] WebSocket 已存在,跳过连接`);return}N(!0);let Es=null;try{const Cs=await ke("/api/webui/ws-token");if(Cs.ok){const rs=await Cs.json();if(rs.success&&rs.token)Es=rs.token;else{console.warn(`[Tab ${V}] 获取 WebSocket token 失败: ${rs.message||"未登录"}`),N(!1);return}}}catch(Cs){console.error(`[Tab ${V}] 获取 WebSocket token 失败:`,Cs),N(!1);return}if(!Es){N(!1);return}const ms=window.location.protocol==="https:"?"wss:":"ws:",Ms=new URLSearchParams;Ms.append("token",Es),Ke==="virtual"&&He?(Ms.append("user_id",He.userId),Ms.append("user_name",He.userName),Ms.append("platform",He.platform),Ms.append("person_id",He.personId),Ms.append("group_name",He.groupName||"WebUI虚拟群聊"),He.groupId&&Ms.append("group_id",He.groupId)):(Ms.append("user_id",Q.current),Ms.append("user_name",y));const We=`${ms}//${window.location.host}/api/chat/ws?${Ms.toString()}`;console.log(`[Tab ${V}] 正在连接 WebSocket:`,We);try{const Cs=new WebSocket(We);B.current.set(V,Cs),Cs.onopen=()=>{$(V,{isConnected:!0}),N(!1),console.log(`[Tab ${V}] WebSocket 已连接`)},Cs.onmessage=rs=>{try{const is=JSON.parse(rs.data);switch(is.type){case"session_info":$(V,{sessionInfo:{session_id:is.session_id,user_id:is.user_id,user_name:is.user_name,bot_name:is.bot_name}});break;case"system":A(V,{id:G("sys"),type:"system",content:is.content||"",timestamp:is.timestamp||Date.now()/1e3});break;case"user_message":{const ys=is.sender?.user_id,rt=Ke==="virtual"&&He?He.userId:Q.current;console.log(`[Tab ${V}] 收到 user_message, sender: ${ys}, current: ${rt}`);const jt=ys?ys.replace(/^webui_user_/,""):"",Ae=rt?rt.replace(/^webui_user_/,""):"";if(jt&&Ae&&jt===Ae){console.log(`[Tab ${V}] 跳过自己的消息(user_id 匹配)`);break}const Qe=fe.current.get(V)||new Set,As=`user-${is.content}-${Math.floor((is.timestamp||0)*1e3)}`;if(Qe.has(As)){console.log(`[Tab ${V}] 跳过自己的消息(内容去重)`);break}if(Qe.add(As),fe.current.set(V,Qe),Qe.size>100){const mt=Qe.values().next().value;mt&&Qe.delete(mt)}A(V,{id:is.message_id||G("user"),type:"user",content:is.content||"",timestamp:is.timestamp||Date.now()/1e3,sender:is.sender});break}case"bot_message":{$(V,{isTyping:!1});const ys=fe.current.get(V)||new Set,rt=`bot-${is.content}-${Math.floor((is.timestamp||0)*1e3)}`;if(ys.has(rt))break;if(ys.add(rt),fe.current.set(V,ys),ys.size>100){const jt=ys.values().next().value;jt&&ys.delete(jt)}c(jt=>jt.map(Ae=>{if(Ae.id!==V)return Ae;const Qe=Ae.messages.filter(mt=>mt.type!=="thinking"),As={id:G("bot"),type:"bot",content:is.content||"",message_type:is.message_type==="rich"?"rich":"text",segments:is.segments,timestamp:is.timestamp||Date.now()/1e3,sender:is.sender};return{...Ae,messages:[...Qe,As]}}));break}case"typing":$(V,{isTyping:is.is_typing||!1});break;case"error":c(ys=>ys.map(rt=>{if(rt.id!==V)return rt;const jt=rt.messages.filter(Ae=>Ae.type!=="thinking");return{...rt,messages:[...jt,{id:G("error"),type:"error",content:is.content||"发生错误",timestamp:is.timestamp||Date.now()/1e3}]}})),Ee({title:"错误",description:is.content,variant:"destructive"});break;case"pong":break;case"history":{const ys=is.messages||[];if(ys.length>0){const rt=fe.current.get(V)||new Set,jt=ys.map(Ae=>{const Qe=Ae.is_bot||!1,As=Ae.id||G(Qe?"bot":"user"),mt=`${Qe?"bot":"user"}-${Ae.content}-${Math.floor(Ae.timestamp*1e3)}`;return rt.add(mt),{id:As,type:Qe?"bot":"user",content:Ae.content,timestamp:Ae.timestamp,sender:{name:Ae.sender_name||(Qe?"麦麦":"用户"),user_id:Ae.sender_id,is_bot:Qe}}});fe.current.set(V,rt),$(V,{messages:jt}),console.log(`[Tab ${V}] 已加载 ${jt.length} 条历史消息`)}break}default:console.log("未知消息类型:",is.type)}}catch(is){console.error("解析消息失败:",is)}},Cs.onclose=()=>{$(V,{isConnected:!1}),N(!1),B.current.delete(V),console.log(`[Tab ${V}] WebSocket 已断开`);const rs=Y.current.get(V);rs&&clearTimeout(rs);const is=window.setTimeout(()=>{if(!J.current){const ys=r.find(rt=>rt.id===V);ys&&cs(V,ys.type,ys.virtualConfig)}},5e3);Y.current.set(V,is)},Cs.onerror=rs=>{console.error(`[Tab ${V}] WebSocket 错误:`,rs),N(!1)}}catch(Cs){console.error(`[Tab ${V}] 创建 WebSocket 失败:`,Cs),N(!1)}},[y,$,A,Ee,r]),J=u.useRef(!1);u.useEffect(()=>{J.current=!1;const V=B.current,Ke=Y.current,He=fe.current;$e("webui-default");const Je=setTimeout(()=>{J.current||(cs("webui-default","webui"),r.forEach(ms=>{ms.type==="virtual"&&ms.virtualConfig&&(He.set(ms.id,new Set),setTimeout(()=>{J.current||cs(ms.id,"virtual",ms.virtualConfig)},200))}))},100),Es=setInterval(()=>{V.forEach(ms=>{ms.readyState===WebSocket.OPEN&&ms.send(JSON.stringify({type:"ping"}))})},3e4);return()=>{J.current=!0,clearTimeout(Je),clearInterval(Es),Ke.forEach(ms=>{clearTimeout(ms)}),Ke.clear(),V.forEach(ms=>{ms.close()}),V.clear()}},[]);const Z=u.useCallback(()=>{const V=B.current.get(d);if(!f.trim()||!V||V.readyState!==WebSocket.OPEN)return;const Ke=h?.type==="virtual"&&h.virtualConfig?.userName||y,He=f.trim(),Je=Date.now()/1e3;V.send(JSON.stringify({type:"message",content:He,user_name:Ke}));const Es=fe.current.get(d)||new Set,ms=`user-${He}-${Math.floor(Je*1e3)}`;if(Es.add(ms),fe.current.set(d,Es),Es.size>100){const Cs=Es.values().next().value;Cs&&Es.delete(Cs)}const Ms={id:G("user"),type:"user",content:He,timestamp:Je,sender:{name:Ke,is_bot:!1}};A(d,Ms);const We={id:G("thinking"),type:"thinking",content:"",timestamp:Je+.001,sender:{name:h?.sessionInfo.bot_name||"麦麦",is_bot:!0}};A(d,We),p("")},[f,y,d,h,A]),Le=V=>{V.key==="Enter"&&!V.shiftKey&&(V.preventDefault(),Z())},le=()=>{F(y),M(!0)},De=()=>{const V=S.trim()||"WebUI用户";w(V),OC(V),M(!1);const Ke=B.current.get(d);Ke?.readyState===WebSocket.OPEN&&Ke.send(JSON.stringify({type:"update_nickname",user_name:V}))},xe=()=>{F(""),M(!1)},Me=V=>new Date(V*1e3).toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"}),ds=()=>{const V=B.current.get(d);V&&(V.close(),B.current.delete(d)),cs(d,h?.type||"webui",h?.virtualConfig)},Ts=()=>{D({platform:"",personId:"",userId:"",userName:"",groupName:"",groupId:""}),ge(""),Re(),C(!0)},Ct=()=>{if(!pe.platform||!pe.personId){Ee({title:"配置不完整",description:"请选择平台和用户",variant:"destructive"});return}const V=`webui_virtual_group_${pe.platform}_${pe.userId}`,Ke=`virtual-${pe.platform}-${pe.userId}-${Date.now()}`,He=pe.userName||pe.userId,Je={id:Ke,type:"virtual",label:He,virtualConfig:{...pe,groupId:V},messages:[],isConnected:!1,isTyping:!1,sessionInfo:{}};c(Es=>{const ms=[...Es,Je],Ms=ms.filter(We=>We.type==="virtual"&&We.virtualConfig).map(We=>({id:We.id,label:We.label,virtualConfig:We.virtualConfig,createdAt:Date.now()}));return nj(Ms),ms}),m(Ke),C(!1),fe.current.set(Ke,new Set),setTimeout(()=>{cs(Ke,"virtual",pe)},100),Ee({title:"虚拟身份标签页",description:`已创建 ${He} 的对话`})},ia=(V,Ke)=>{if(Ke?.stopPropagation(),V==="webui-default")return;const He=B.current.get(V);He&&(He.close(),B.current.delete(V));const Je=Y.current.get(V);Je&&(clearTimeout(Je),Y.current.delete(V)),fe.current.delete(V),c(Es=>{const ms=Es.filter(We=>We.id!==V),Ms=ms.filter(We=>We.type==="virtual"&&We.virtualConfig).map(We=>({id:We.id,label:We.label,virtualConfig:We.virtualConfig,createdAt:Date.now()}));return nj(Ms),ms}),d===V&&m("webui-default")},ut=V=>{m(V)},Is=V=>{D(Ke=>({...Ke,personId:V.person_id,userId:V.user_id,userName:V.nickname||V.person_name}))};return e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsx(Qs,{open:E,onOpenChange:C,children:e.jsxs(Hs,{className:"sm:max-w-[500px] max-h-[85vh] overflow-hidden flex flex-col",children:[e.jsxs(qs,{children:[e.jsxs(Vs,{className:"flex items-center gap-2",children:[e.jsx(Am,{className:"h-5 w-5"}),"新建虚拟身份对话"]}),e.jsx(at,{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(Go,{className:"h-4 w-4"}),"选择平台"]}),e.jsxs(Pe,{value:pe.platform,onValueChange:V=>{D(Ke=>({...Ke,platform:V,personId:"",userId:"",userName:""})),X([])},children:[e.jsx(Be,{disabled:L,children:e.jsx(Fe,{placeholder:L?"加载中...":"选择平台"})}),e.jsx(Ie,{children:R.map(V=>e.jsxs(W,{value:V.platform,children:[V.platform," (",V.count," 人)"]},V.platform))})]})]}),pe.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(oc,{className:"h-4 w-4"}),"选择用户"]}),e.jsxs("div",{className:"relative",children:[e.jsx($t,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ne,{placeholder:"搜索用户名...",value:ce,onChange:V=>ge(V.target.value),className:"pl-9"})]}),e.jsx(ts,{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(Fs,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):O.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-muted-foreground",children:[e.jsx(oc,{className:"h-8 w-8 mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"没有找到用户"})]}):e.jsx("div",{className:"space-y-1",children:O.map(V=>e.jsxs("button",{onClick:()=>Is(V),className:P("w-full flex items-center gap-3 p-2 rounded-md text-left transition-colors",pe.personId===V.person_id?"bg-primary text-primary-foreground":"hover:bg-muted"),children:[e.jsx(ec,{className:"h-8 w-8 shrink-0",children:e.jsx(sc,{className:P("text-xs",pe.personId===V.person_id?"bg-primary-foreground/20":"bg-muted"),children:(V.nickname||V.person_name||"?").charAt(0)})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"font-medium truncate",children:V.nickname||V.person_name}),e.jsxs("div",{className:P("text-xs truncate",pe.personId===V.person_id?"text-primary-foreground/70":"text-muted-foreground"),children:["ID: ",V.user_id,V.is_known&&" · 已认识"]})]})]},V.person_id))})})})]}),pe.personId&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"虚拟群名(可选)"}),e.jsx(ne,{placeholder:"WebUI虚拟群聊",value:pe.groupName,onChange:V=>D(Ke=>({...Ke,groupName:V.target.value}))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"麦麦会认为这是一个名为此名称的群聊"})]})]}),e.jsxs(gt,{className:"gap-2 sm:gap-0",children:[e.jsx(_,{variant:"outline",onClick:()=>C(!1),children:"取消"}),e.jsx(_,{onClick:Ct,disabled:!pe.platform||!pe.personId,children:"创建对话"})]})]})}),e.jsx("div",{className:"shrink-0 border-b bg-muted/30",children:e.jsx("div",{className:"max-w-4xl mx-auto px-2 sm:px-4",children:e.jsxs("div",{className:"flex items-center gap-1 overflow-x-auto py-1.5 scrollbar-thin",children:[r.map(V=>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",d===V.id?"bg-background shadow-sm border":"text-muted-foreground"),onClick:()=>ut(V.id),children:[V.type==="webui"?e.jsx(Ia,{className:"h-3.5 w-3.5"}):e.jsx(Am,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"max-w-[100px] truncate",children:V.label}),e.jsx("span",{className:P("w-1.5 h-1.5 rounded-full",V.isConnected?"bg-green-500":"bg-muted-foreground/50")}),V.id!=="webui-default"&&e.jsx("span",{onClick:Ke=>ia(V.id,Ke),className:"ml-0.5 p-0.5 rounded hover:bg-muted-foreground/20 cursor-pointer",role:"button",tabIndex:0,onKeyDown:Ke=>{(Ke.key==="Enter"||Ke.key===" ")&&(Ke.preventDefault(),ia(V.id,Ke))},children:e.jsx(Sa,{className:"h-3 w-3"})})]},V.id)),e.jsx("button",{onClick:Ts,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(Xs,{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(ec,{className:"h-8 w-8 sm:h-10 sm:w-10 shrink-0",children:e.jsx(sc,{className:"bg-primary/10 text-primary",children:e.jsx(Yn,{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(Y1,{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(Fs,{className:"h-3 w-3 animate-spin"}),e.jsx("span",{children:"连接中..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(J1,{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:[j&&e.jsx(Fs,{className:"h-4 w-4 animate-spin text-muted-foreground"}),e.jsx(_,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:ds,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(Am,{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(Fl,{className:"h-3 w-3"}),e.jsx("span",{children:"当前身份:"}),z?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ne,{value:S,onChange:V=>F(V.target.value),onKeyDown:V=>{V.key==="Enter"&&De(),V.key==="Escape"&&xe()},className:"h-7 w-32",placeholder:"输入昵称",autoFocus:!0}),e.jsx(_,{size:"sm",variant:"ghost",className:"h-7 px-2",onClick:De,children:"保存"}),e.jsx(_,{size:"sm",variant:"ghost",className:"h-7 px-2",onClick:xe,children:"取消"})]}):e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"font-medium text-foreground",children:y}),e.jsx(_,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:le,title:"修改昵称",children:e.jsx(X1,{className:"h-3 w-3"})})]})]})})]})}),e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx(ts,{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&&!j&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx(Yn,{className:"h-12 w-12 mb-4 opacity-50"}),e.jsxs("p",{className:"text-sm",children:["开始与 ",h?.sessionInfo.bot_name||"麦麦"," 对话吧!"]})]}),h?.messages.map(V=>e.jsxs("div",{className:P("flex gap-2 sm:gap-3",V.type==="user"&&"flex-row-reverse",V.type==="system"&&"justify-center",V.type==="error"&&"justify-center"),children:[V.type==="system"&&e.jsx("div",{className:"text-xs text-muted-foreground bg-muted/50 px-3 py-1 rounded-full max-w-[90%]",children:V.content}),V.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:V.content}),V.type==="thinking"&&e.jsxs(e.Fragment,{children:[e.jsx(ec,{className:"h-7 w-7 sm:h-8 sm:w-8 shrink-0",children:e.jsx(sc,{className:"bg-primary/10 text-primary",children:e.jsx(Yn,{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:V.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:"思考中..."})]})})]})]}),(V.type==="user"||V.type==="bot")&&e.jsxs(e.Fragment,{children:[e.jsx(ec,{className:"h-7 w-7 sm:h-8 sm:w-8 shrink-0",children:e.jsx(sc,{className:P("text-xs",V.type==="bot"?"bg-primary/10 text-primary":"bg-secondary text-secondary-foreground"),children:V.type==="bot"?e.jsx(Yn,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4"}):e.jsx(Fl,{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%]",V.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:V.sender?.name||(V.type==="bot"?h?.sessionInfo.bot_name:y)}),e.jsx("span",{children:Me(V.timestamp)})]}),e.jsx("div",{className:P("rounded-2xl px-3 py-2 text-sm break-words",V.type==="bot"?"bg-muted rounded-tl-sm":"bg-primary text-primary-foreground rounded-tr-sm"),children:e.jsx($C,{message:V,isBot:V.type==="bot"})})]})]})]},V.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(ne,{value:f,onChange:V=>p(V.target.value),onKeyDown:Le,placeholder:h?.isConnected?"输入消息...":"等待连接...",disabled:!h?.isConnected,className:"flex-1 h-10 sm:h-10"}),e.jsx(_,{onClick:Z,disabled:!h?.isConnected||!f.trim(),size:"icon",className:"h-10 w-10 shrink-0",children:e.jsx(Z1,{className:"h-4 w-4"})})]})})})]})}var zx="Radio",[IC,_N]=ld(zx),[PC,FC]=IC(zx),SN=u.forwardRef((a,l)=>{const{__scopeRadio:r,name:c,checked:d=!1,required:m,disabled:h,value:f="on",onCheck:p,form:g,...N}=a,[j,b]=u.useState(null),y=nd(l,M=>b(M)),w=u.useRef(!1),z=j?g||!!j.closest("form"):!0;return e.jsxs(PC,{scope:r,checked:d,disabled:h,children:[e.jsx(ar.button,{type:"button",role:"radio","aria-checked":d,"data-state":EN(d),"data-disabled":h?"":void 0,disabled:h,value:f,...N,ref:y,onClick:_n(a.onClick,M=>{d||p?.(),z&&(w.current=M.isPropagationStopped(),w.current||M.stopPropagation())})}),z&&e.jsx(TN,{control:j,bubbles:!w.current,name:c,value:f,checked:d,required:m,disabled:h,form:g,style:{transform:"translateX(-100%)"}})]})});SN.displayName=zx;var kN="RadioIndicator",CN=u.forwardRef((a,l)=>{const{__scopeRadio:r,forceMount:c,...d}=a,m=FC(kN,r);return e.jsx(b1,{present:c||m.checked,children:e.jsx(ar.span,{"data-state":EN(m.checked),"data-disabled":m.disabled?"":void 0,...d,ref:l})})});CN.displayName=kN;var HC="RadioBubbleInput",TN=u.forwardRef(({__scopeRadio:a,control:l,checked:r,bubbles:c=!0,...d},m)=>{const h=u.useRef(null),f=nd(h,m),p=y1(r),g=w1(l);return u.useEffect(()=>{const N=h.current;if(!N)return;const j=window.HTMLInputElement.prototype,y=Object.getOwnPropertyDescriptor(j,"checked").set;if(p!==r&&y){const w=new Event("click",{bubbles:c});y.call(N,r),N.dispatchEvent(w)}},[p,r,c]),e.jsx(ar.input,{type:"radio","aria-hidden":!0,defaultChecked:r,...d,tabIndex:-1,ref:f,style:{...d.style,...g,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});TN.displayName=HC;function EN(a){return a?"checked":"unchecked"}var qC=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],gd="RadioGroup",[VC]=ld(gd,[Dj,_N]),MN=Dj(),AN=_N(),[GC,KC]=VC(gd),zN=u.forwardRef((a,l)=>{const{__scopeRadioGroup:r,name:c,defaultValue:d,value:m,required:h=!1,disabled:f=!1,orientation:p,dir:g,loop:N=!0,onValueChange:j,...b}=a,y=MN(r),w=Wj(g),[z,M]=ad({prop:m,defaultProp:d??null,onChange:j,caller:gd});return e.jsx(GC,{scope:r,name:c,required:h,disabled:f,value:z,onValueChange:M,children:e.jsx(Rw,{asChild:!0,...y,orientation:p,dir:w,loop:N,children:e.jsx(ar.div,{role:"radiogroup","aria-required":h,"aria-orientation":p,"data-disabled":f?"":void 0,dir:w,...b,ref:l})})})});zN.displayName=gd;var RN="RadioGroupItem",DN=u.forwardRef((a,l)=>{const{__scopeRadioGroup:r,disabled:c,...d}=a,m=KC(RN,r),h=m.disabled||c,f=MN(r),p=AN(r),g=u.useRef(null),N=nd(l,g),j=m.value===d.value,b=u.useRef(!1);return u.useEffect(()=>{const y=z=>{qC.includes(z.key)&&(b.current=!0)},w=()=>b.current=!1;return document.addEventListener("keydown",y),document.addEventListener("keyup",w),()=>{document.removeEventListener("keydown",y),document.removeEventListener("keyup",w)}},[]),e.jsx(Dw,{asChild:!0,...f,focusable:!h,active:j,children:e.jsx(SN,{disabled:h,required:m.required,checked:j,...p,...d,name:m.name,ref:N,onCheck:()=>m.onValueChange(d.value),onKeyDown:_n(y=>{y.key==="Enter"&&y.preventDefault()}),onFocus:_n(d.onFocus,()=>{b.current&&g.current?.click()})})})});DN.displayName=RN;var QC="RadioGroupIndicator",ON=u.forwardRef((a,l)=>{const{__scopeRadioGroup:r,...c}=a,d=AN(r);return e.jsx(CN,{...d,...c,ref:l})});ON.displayName=QC;var LN=zN,UN=DN,YC=ON;const Rx=u.forwardRef(({className:a,...l},r)=>e.jsx(LN,{className:P("grid gap-2",a),...l,ref:r}));Rx.displayName=LN.displayName;const Wo=u.forwardRef(({className:a,...l},r)=>e.jsx(UN,{ref:r,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",a),...l,children:e.jsx(YC,{className:"flex items-center justify-center",children:e.jsx(Vo,{className:"h-2.5 w-2.5 fill-current text-current"})})}));Wo.displayName=UN.displayName;function JC({question:a,value:l,onChange:r,error:c,disabled:d=!1}){const[m,h]=u.useState(null),f=d||a.readOnly,p=()=>{switch(a.type){case"single":return e.jsx(Rx,{value:l||"",onValueChange:r,disabled:f,className:"space-y-2",children:a.options?.map(g=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Wo,{value:g.value,id:`${a.id}-${g.id}`}),e.jsx(T,{htmlFor:`${a.id}-${g.id}`,className:"cursor-pointer font-normal",children:g.label})]},g.id))});case"multiple":{const g=l||[];return e.jsxs("div",{className:"space-y-2",children:[a.options?.map(N=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(tt,{id:`${a.id}-${N.id}`,checked:g.includes(N.value),disabled:f||a.maxSelections!==void 0&&g.length>=a.maxSelections&&!g.includes(N.value),onCheckedChange:j=>{r(j?[...g,N.value]:g.filter(b=>b!==N.value))}}),e.jsx(T,{htmlFor:`${a.id}-${N.id}`,className:"cursor-pointer font-normal",children:N.label})]},N.id)),a.maxSelections&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["最多选择 ",a.maxSelections," 项"]})]})}case"text":return e.jsx(ne,{value:l||"",onChange:g=>r(g.target.value),placeholder:a.placeholder||"请输入...",disabled:f,readOnly:a.readOnly,maxLength:a.maxLength,className:P(a.readOnly&&"bg-muted cursor-not-allowed")});case"textarea":return e.jsxs("div",{className:"space-y-1",children:[e.jsx(pt,{value:l||"",onChange:g=>r(g.target.value),placeholder:a.placeholder||"请输入...",disabled:f,readOnly:a.readOnly,maxLength:a.maxLength,rows:4,className:P(a.readOnly&&"bg-muted cursor-not-allowed")}),a.maxLength&&e.jsxs("p",{className:"text-xs text-muted-foreground text-right",children:[(l||"").length," / ",a.maxLength]})]});case"rating":{const g=l||0,N=m!==null?m:g;return e.jsxs("div",{className:"flex items-center gap-1",children:[[1,2,3,4,5].map(j=>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(j),onMouseLeave:()=>h(null),onClick:()=>!f&&r(j),children:e.jsx(vn,{className:P("h-6 w-6 transition-colors",j<=N?"fill-yellow-400 text-yellow-400":"text-muted-foreground")})},j)),g>0&&e.jsxs("span",{className:"ml-2 text-sm text-muted-foreground",children:[g," / 5"]})]})}case"scale":{const g=a.min??1,N=a.max??10,j=a.step??1,b=l??g;return e.jsxs("div",{className:"space-y-4",children:[e.jsx(el,{value:[b],onValueChange:([y])=>r(y),min:g,max:N,step:j,disabled:f}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:a.minLabel||g}),e.jsx("span",{className:"font-medium text-foreground",children:b}),e.jsx("span",{children:a.maxLabel||N})]})]})}case"dropdown":return e.jsxs(Pe,{value:l||"",onValueChange:r,disabled:f,children:[e.jsx(Be,{children:e.jsx(Fe,{placeholder:a.placeholder||"请选择..."})}),e.jsx(Ie,{children:a.options?.map(g=>e.jsx(W,{value:g.value,children:g.label},g.id))})]});default:return e.jsx("div",{className:"text-muted-foreground",children:"不支持的问题类型"})}};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs(T,{className:"text-base font-medium",children:[a.title,a.required&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),a.description&&e.jsx("p",{className:"text-sm text-muted-foreground",children:a.description})]}),p(),c&&e.jsx("p",{className:"text-sm text-destructive",children:c})]})}const $N="https://maibot-plugin-stats.maibot-webui.workers.dev";function BN(){const a="maibot_user_id";let l=localStorage.getItem(a);if(!l){const r=Math.random().toString(36).substring(2,10),c=Date.now().toString(36),d=Math.random().toString(36).substring(2,10);l=`fp_${r}_${c}_${d}`,localStorage.setItem(a,l)}return l}async function XC(a,l,r,c){try{const d=c?.userId||BN(),m={surveyId:a,surveyVersion:l,userId:d,answers:r,submittedAt:new Date().toISOString(),allowMultiple:c?.allowMultiple,metadata:{userAgent:navigator.userAgent,language:navigator.language}},h=await fetch(`${$N}/survey/submit`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(m)}),f=await h.json();return h.status===429?{success:!1,error:"提交过于频繁,请稍后再试"}:h.status===409?{success:!1,error:f.error||"你已经提交过这份问卷了"}:h.ok?{success:!0,submissionId:f.submissionId,message:f.message}:{success:!1,error:f.error||"提交失败"}}catch(d){return console.error("Error submitting survey:",d),{success:!1,error:"网络错误"}}}async function ZC(a,l){try{const r=l||BN(),c=new URLSearchParams({user_id:r,survey_id:a}),d=await fetch(`${$N}/survey/check?${c}`);return d.ok?{success:!0,hasSubmitted:(await d.json()).hasSubmitted}:{success:!1,error:(await d.json()).error||"检查失败"}}catch(r){return console.error("Error checking submission:",r),{success:!1,error:"网络错误"}}}function IN({config:a,initialAnswers:l,onSubmitSuccess:r,onSubmitError:c,showProgress:d=!0,paginateQuestions:m=!1,className:h}){const f=u.useCallback(()=>!l||l.length===0?{}:l.reduce((B,ue)=>(B[ue.questionId]=ue.value,B),{}),[l]),[p,g]=u.useState(()=>f()),[N,j]=u.useState({}),[b,y]=u.useState(0),[w,z]=u.useState(!1),[M,S]=u.useState(!1),[F,E]=u.useState(null),[C,R]=u.useState(null),[H,O]=u.useState(!1),[X,L]=u.useState(!0);u.useEffect(()=>{l&&l.length>0&&g(B=>({...B,...f()}))},[l,f]),u.useEffect(()=>{(async()=>{if(!a.settings?.allowMultiple){const ue=await ZC(a.id);ue.success&&ue.hasSubmitted&&O(!0)}L(!1)})()},[a.id,a.settings?.allowMultiple]);const me=u.useCallback(()=>{const B=new Date;return!(a.settings?.startTime&&new Date(a.settings.startTime)>B||a.settings?.endTime&&new Date(a.settings.endTime){const ue=p[B.id];return ue==null?!1:Array.isArray(ue)?ue.length>0:typeof ue=="string"?ue.trim()!=="":!0}).length,je=Ne/a.questions.length*100,ce=u.useCallback((B,ue)=>{g(Y=>({...Y,[B]:ue})),j(Y=>{const we={...Y};return delete we[B],we})},[]),ge=u.useCallback(()=>{const B={};for(const ue of a.questions){if(ue.required){const Y=p[ue.id];if(Y==null){B[ue.id]="此题为必填项";continue}if(Array.isArray(Y)&&Y.length===0){B[ue.id]="请至少选择一项";continue}if(typeof Y=="string"&&Y.trim()===""){B[ue.id]="此题为必填项";continue}}ue.minLength&&typeof p[ue.id]=="string"&&p[ue.id].length{if(!ge()){if(m){const B=a.questions.findIndex(ue=>N[ue.id]);B>=0&&y(B)}return}z(!0),E(null);try{const B=a.questions.filter(Y=>p[Y.id]!==void 0).map(Y=>({questionId:Y.id,value:p[Y.id]})),ue=await XC(a.id,a.version,B,{allowMultiple:a.settings?.allowMultiple});if(ue.success&&ue.submissionId)S(!0),R(ue.submissionId),r?.(ue.submissionId);else{const Y=ue.error||"提交失败";E(Y),c?.(Y)}}catch(B){const ue=B instanceof Error?B.message:"提交失败";E(ue),c?.(ue)}finally{z(!1)}},[ge,m,a,p,N,r,c]),D=u.useCallback(B=>{B>=0&&Be.jsxs("div",{className:P("p-4 rounded-lg border bg-card",N[B.id]?"border-destructive bg-destructive/5":"border-border"),children:[m&&e.jsxs("div",{className:"text-xs text-muted-foreground mb-2",children:["问题 ",b+1," / ",a.questions.length]}),!m&&e.jsxs("div",{className:"text-xs text-muted-foreground mb-2",children:[ue+1,"."]}),e.jsx(JC,{question:B,value:p[B.id],onChange:Y=>ce(B.id,Y),error:N[B.id],disabled:w})]},B.id)),F&&e.jsxs(ht,{variant:"destructive",children:[e.jsx(Ut,{className:"h-4 w-4"}),e.jsx(ft,{children:F})]}),e.jsx("div",{className:"flex justify-between items-center py-4",children:m?e.jsxs(e.Fragment,{children:[e.jsxs(_,{variant:"outline",onClick:()=>D(b-1),disabled:b===0||w,children:[e.jsx(Pa,{className:"h-4 w-4 mr-1"}),"上一题"]}),b===a.questions.length-1?e.jsxs(_,{onClick:pe,disabled:w,children:[w&&e.jsx(Fs,{className:"h-4 w-4 mr-2 animate-spin"}),"提交问卷"]}):e.jsxs(_,{onClick:()=>D(b+1),disabled:w,children:["下一题",e.jsx(ra,{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:pe,disabled:w,size:"lg",children:[w&&e.jsx(Fs,{className:"h-4 w-4 mr-2 animate-spin"}),"提交问卷"]})]})})]})})]})}const WC={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:"感谢你的反馈!你的意见对我们非常重要,我们会认真考虑每一条建议。"}},e3={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 s3(){const[a,l]=u.useState(!0),r=u.useMemo(()=>JSON.parse(JSON.stringify(WC)),[]);u.useEffect(()=>{l(!1)},[]);const c=u.useMemo(()=>[{questionId:"webui_version",value:`v${ud}`}],[]),d=u.useCallback(h=>{console.log("WebUI Survey submitted:",h)},[]),m=u.useCallback(h=>{console.error("WebUI Survey submission error:",h)},[]);return a?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(Fs,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):r?e.jsxs("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:[e.jsxs("div",{className:"mb-4 sm:mb-6 shrink-0",children:[e.jsxs("h1",{className:"text-2xl sm:text-3xl font-bold flex items-center gap-2",children:[e.jsx(pv,{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(IN,{config:r,initialAnswers:c,showProgress:!0,paginateQuestions:!1,onSubmitSuccess:d,onSubmitError:m})})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center min-h-[400px] gap-4",children:[e.jsxs(ht,{variant:"destructive",className:"max-w-md",children:[e.jsx(Ut,{className:"h-4 w-4"}),e.jsx(ft,{children:"无法加载问卷配置"})]}),e.jsx(_,{variant:"outline",onClick:()=>window.location.reload(),children:"重试"})]})}function t3(){const[a,l]=u.useState(null),[r,c]=u.useState(!0),[d,m]=u.useState("未知版本");u.useEffect(()=>{(async()=>{try{const j=await V_();m(j.version||"未知版本")}catch(j){console.error("Failed to get MaiBot version:",j),m("获取失败")}const N=JSON.parse(JSON.stringify(e3));l(N),c(!1)})()},[]);const h=u.useMemo(()=>[{questionId:"maibot_version",value:d}],[d]),f=u.useCallback(g=>{console.log("MaiBot Survey submitted:",g)},[]),p=u.useCallback(g=>{console.error("MaiBot Survey submission error:",g)},[]);return r?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(Fs,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):a?e.jsxs("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:[e.jsxs("div",{className:"mb-4 sm:mb-6 shrink-0",children:[e.jsxs("h1",{className:"text-2xl sm:text-3xl font-bold flex items-center gap-2",children:[e.jsx(pv,{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(IN,{config:a,initialAnswers:h,showProgress:!0,paginateQuestions:!1,onSubmitSuccess:f,onSubmitError:p})})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center min-h-[400px] gap-4",children:[e.jsxs(ht,{variant:"destructive",className:"max-w-md",children:[e.jsx(Ut,{className:"h-4 w-4"}),e.jsx(ft,{children:"无法加载问卷配置"})]}),e.jsx(_,{variant:"outline",onClick:()=>window.location.reload(),children:"重试"})]})}async function a3(a=2025){const l=await ke(`/api/webui/annual-report/full?year=${a}`);if(!l.ok){const r=await l.json();throw new Error(r.detail||"获取年度报告失败")}return l.json()}function l3(a,l){if(a.match(/^[a-z]+:\/\//i))return a;if(a.match(/^\/\//))return window.location.protocol+a;if(a.match(/^[a-z]+:/i))return a;const r=document.implementation.createHTMLDocument(),c=r.createElement("base"),d=r.createElement("a");return r.head.appendChild(c),r.body.appendChild(d),l&&(c.href=l),d.href=a,d.href}const n3=(()=>{let a=0;const l=()=>`0000${(Math.random()*36**4<<0).toString(36)}`.slice(-4);return()=>(a+=1,`u${l()}${a}`)})();function wn(a){const l=[];for(let r=0,c=a.length;rOa||a.height>Oa)&&(a.width>Oa&&a.height>Oa?a.width>a.height?(a.height*=Oa/a.width,a.width=Oa):(a.width*=Oa/a.height,a.height=Oa):a.width>Oa?(a.height*=Oa/a.width,a.width=Oa):(a.width*=Oa/a.height,a.height=Oa))}function sd(a){return new Promise((l,r)=>{const c=new Image;c.onload=()=>{c.decode().then(()=>{requestAnimationFrame(()=>l(c))})},c.onerror=r,c.crossOrigin="anonymous",c.decoding="async",c.src=a})}async function d3(a){return Promise.resolve().then(()=>new XMLSerializer().serializeToString(a)).then(encodeURIComponent).then(l=>`data:image/svg+xml;charset=utf-8,${l}`)}async function u3(a,l,r){const c="http://www.w3.org/2000/svg",d=document.createElementNS(c,"svg"),m=document.createElementNS(c,"foreignObject");return d.setAttribute("width",`${l}`),d.setAttribute("height",`${r}`),d.setAttribute("viewBox",`0 0 ${l} ${r}`),m.setAttribute("width","100%"),m.setAttribute("height","100%"),m.setAttribute("x","0"),m.setAttribute("y","0"),m.setAttribute("externalResourcesRequired","true"),d.appendChild(m),m.appendChild(a),d3(d)}const _a=(a,l)=>{if(a instanceof l)return!0;const r=Object.getPrototypeOf(a);return r===null?!1:r.constructor.name===l.name||_a(r,l)};function m3(a){const l=a.getPropertyValue("content");return`${a.cssText} content: '${l.replace(/'|"/g,"")}';`}function x3(a,l){return PN(l).map(r=>{const c=a.getPropertyValue(r),d=a.getPropertyPriority(r);return`${r}: ${c}${d?" !important":""};`}).join(" ")}function h3(a,l,r,c){const d=`.${a}:${l}`,m=r.cssText?m3(r):x3(r,c);return document.createTextNode(`${d}{${m}}`)}function rj(a,l,r,c){const d=window.getComputedStyle(a,r),m=d.getPropertyValue("content");if(m===""||m==="none")return;const h=n3();try{l.className=`${l.className} ${h}`}catch{return}const f=document.createElement("style");f.appendChild(h3(h,r,d,c)),l.appendChild(f)}function f3(a,l,r){rj(a,l,":before",r),rj(a,l,":after",r)}const ij="application/font-woff",cj="image/jpeg",p3={woff:ij,woff2:ij,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:cj,jpeg:cj,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml",webp:"image/webp"};function g3(a){const l=/\.([^./]*?)$/g.exec(a);return l?l[1]:""}function Dx(a){const l=g3(a).toLowerCase();return p3[l]||""}function j3(a){return a.split(/,/)[1]}function ax(a){return a.search(/^(data:)/)!==-1}function v3(a,l){return`data:${l};base64,${a}`}async function HN(a,l,r){const c=await fetch(a,l);if(c.status===404)throw new Error(`Resource "${c.url}" not found`);const d=await c.blob();return new Promise((m,h)=>{const f=new FileReader;f.onerror=h,f.onloadend=()=>{try{m(r({res:c,result:f.result}))}catch(p){h(p)}},f.readAsDataURL(d)})}const Km={};function N3(a,l,r){let c=a.replace(/\?.*/,"");return r&&(c=a),/ttf|otf|eot|woff2?/i.test(c)&&(c=c.replace(/.*\//,"")),l?`[${l}]${c}`:c}async function Ox(a,l,r){const c=N3(a,l,r.includeQueryParams);if(Km[c]!=null)return Km[c];r.cacheBust&&(a+=(/\?/.test(a)?"&":"?")+new Date().getTime());let d;try{const m=await HN(a,r.fetchRequestInit,({res:h,result:f})=>(l||(l=h.headers.get("Content-Type")||""),j3(f)));d=v3(m,l)}catch(m){d=r.imagePlaceholder||"";let h=`Failed to fetch resource: ${a}`;m&&(h=typeof m=="string"?m:m.message),h&&console.warn(h)}return Km[c]=d,d}async function b3(a){const l=a.toDataURL();return l==="data:,"?a.cloneNode(!1):sd(l)}async function y3(a,l){if(a.currentSrc){const m=document.createElement("canvas"),h=m.getContext("2d");m.width=a.clientWidth,m.height=a.clientHeight,h?.drawImage(a,0,0,m.width,m.height);const f=m.toDataURL();return sd(f)}const r=a.poster,c=Dx(r),d=await Ox(r,c,l);return sd(d)}async function w3(a,l){var r;try{if(!((r=a?.contentDocument)===null||r===void 0)&&r.body)return await jd(a.contentDocument.body,l,!0)}catch{}return a.cloneNode(!1)}async function _3(a,l){return _a(a,HTMLCanvasElement)?b3(a):_a(a,HTMLVideoElement)?y3(a,l):_a(a,HTMLIFrameElement)?w3(a,l):a.cloneNode(qN(a))}const S3=a=>a.tagName!=null&&a.tagName.toUpperCase()==="SLOT",qN=a=>a.tagName!=null&&a.tagName.toUpperCase()==="SVG";async function k3(a,l,r){var c,d;if(qN(l))return l;let m=[];return S3(a)&&a.assignedNodes?m=wn(a.assignedNodes()):_a(a,HTMLIFrameElement)&&(!((c=a.contentDocument)===null||c===void 0)&&c.body)?m=wn(a.contentDocument.body.childNodes):m=wn(((d=a.shadowRoot)!==null&&d!==void 0?d:a).childNodes),m.length===0||_a(a,HTMLVideoElement)||await m.reduce((h,f)=>h.then(()=>jd(f,r)).then(p=>{p&&l.appendChild(p)}),Promise.resolve()),l}function C3(a,l,r){const c=l.style;if(!c)return;const d=window.getComputedStyle(a);d.cssText?(c.cssText=d.cssText,c.transformOrigin=d.transformOrigin):PN(r).forEach(m=>{let h=d.getPropertyValue(m);m==="font-size"&&h.endsWith("px")&&(h=`${Math.floor(parseFloat(h.substring(0,h.length-2)))-.1}px`),_a(a,HTMLIFrameElement)&&m==="display"&&h==="inline"&&(h="block"),m==="d"&&l.getAttribute("d")&&(h=`path(${l.getAttribute("d")})`),c.setProperty(m,h,d.getPropertyPriority(m))})}function T3(a,l){_a(a,HTMLTextAreaElement)&&(l.innerHTML=a.value),_a(a,HTMLInputElement)&&l.setAttribute("value",a.value)}function E3(a,l){if(_a(a,HTMLSelectElement)){const c=Array.from(l.children).find(d=>a.value===d.getAttribute("value"));c&&c.setAttribute("selected","")}}function M3(a,l,r){return _a(l,Element)&&(C3(a,l,r),f3(a,l,r),T3(a,l),E3(a,l)),l}async function A3(a,l){const r=a.querySelectorAll?a.querySelectorAll("use"):[];if(r.length===0)return a;const c={};for(let m=0;m_3(c,l)).then(c=>k3(a,c,l)).then(c=>M3(a,c,l)).then(c=>A3(c,l))}const VN=/url\((['"]?)([^'"]+?)\1\)/g,z3=/url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g,R3=/src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;function D3(a){const l=a.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1");return new RegExp(`(url\\(['"]?)(${l})(['"]?\\))`,"g")}function O3(a){const l=[];return a.replace(VN,(r,c,d)=>(l.push(d),r)),l.filter(r=>!ax(r))}async function L3(a,l,r,c,d){try{const m=r?l3(l,r):l,h=Dx(l);let f;return d||(f=await Ox(m,h,c)),a.replace(D3(l),`$1${f}$3`)}catch{}return a}function U3(a,{preferredFontFormat:l}){return l?a.replace(R3,r=>{for(;;){const[c,,d]=z3.exec(r)||[];if(!d)return"";if(d===l)return`src: ${c};`}}):a}function GN(a){return a.search(VN)!==-1}async function KN(a,l,r){if(!GN(a))return a;const c=U3(a,r);return O3(c).reduce((m,h)=>m.then(f=>L3(f,h,l,r)),Promise.resolve(c))}async function Vr(a,l,r){var c;const d=(c=l.style)===null||c===void 0?void 0:c.getPropertyValue(a);if(d){const m=await KN(d,null,r);return l.style.setProperty(a,m,l.style.getPropertyPriority(a)),!0}return!1}async function $3(a,l){await Vr("background",a,l)||await Vr("background-image",a,l),await Vr("mask",a,l)||await Vr("-webkit-mask",a,l)||await Vr("mask-image",a,l)||await Vr("-webkit-mask-image",a,l)}async function B3(a,l){const r=_a(a,HTMLImageElement);if(!(r&&!ax(a.src))&&!(_a(a,SVGImageElement)&&!ax(a.href.baseVal)))return;const c=r?a.src:a.href.baseVal,d=await Ox(c,Dx(c),l);await new Promise((m,h)=>{a.onload=m,a.onerror=l.onImageErrorHandler?(...p)=>{try{m(l.onImageErrorHandler(...p))}catch(g){h(g)}}:h;const f=a;f.decode&&(f.decode=m),f.loading==="lazy"&&(f.loading="eager"),r?(a.srcset="",a.src=d):a.href.baseVal=d})}async function I3(a,l){const c=wn(a.childNodes).map(d=>QN(d,l));await Promise.all(c).then(()=>a)}async function QN(a,l){_a(a,Element)&&(await $3(a,l),await B3(a,l),await I3(a,l))}function P3(a,l){const{style:r}=a;l.backgroundColor&&(r.backgroundColor=l.backgroundColor),l.width&&(r.width=`${l.width}px`),l.height&&(r.height=`${l.height}px`);const c=l.style;return c!=null&&Object.keys(c).forEach(d=>{r[d]=c[d]}),a}const oj={};async function dj(a){let l=oj[a];if(l!=null)return l;const c=await(await fetch(a)).text();return l={url:a,cssText:c},oj[a]=l,l}async function uj(a,l){let r=a.cssText;const c=/url\(["']?([^"')]+)["']?\)/g,m=(r.match(/url\([^)]+\)/g)||[]).map(async h=>{let f=h.replace(c,"$1");return f.startsWith("https://")||(f=new URL(f,a.url).href),HN(f,l.fetchRequestInit,({result:p})=>(r=r.replace(h,`url(${p})`),[h,p]))});return Promise.all(m).then(()=>r)}function mj(a){if(a==null)return[];const l=[],r=/(\/\*[\s\S]*?\*\/)/gi;let c=a.replace(r,"");const d=new RegExp("((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})","gi");for(;;){const p=d.exec(c);if(p===null)break;l.push(p[0])}c=c.replace(d,"");const m=/@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi,h="((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})",f=new RegExp(h,"gi");for(;;){let p=m.exec(c);if(p===null){if(p=f.exec(c),p===null)break;m.lastIndex=f.lastIndex}else f.lastIndex=m.lastIndex;l.push(p[0])}return l}async function F3(a,l){const r=[],c=[];return a.forEach(d=>{if("cssRules"in d)try{wn(d.cssRules||[]).forEach((m,h)=>{if(m.type===CSSRule.IMPORT_RULE){let f=h+1;const p=m.href,g=dj(p).then(N=>uj(N,l)).then(N=>mj(N).forEach(j=>{try{d.insertRule(j,j.startsWith("@import")?f+=1:d.cssRules.length)}catch(b){console.error("Error inserting rule from remote css",{rule:j,error:b})}})).catch(N=>{console.error("Error loading remote css",N.toString())});c.push(g)}})}catch(m){const h=a.find(f=>f.href==null)||document.styleSheets[0];d.href!=null&&c.push(dj(d.href).then(f=>uj(f,l)).then(f=>mj(f).forEach(p=>{h.insertRule(p,h.cssRules.length)})).catch(f=>{console.error("Error loading remote stylesheet",f)})),console.error("Error inlining remote css file",m)}}),Promise.all(c).then(()=>(a.forEach(d=>{if("cssRules"in d)try{wn(d.cssRules||[]).forEach(m=>{r.push(m)})}catch(m){console.error(`Error while reading CSS rules from ${d.href}`,m)}}),r))}function H3(a){return a.filter(l=>l.type===CSSRule.FONT_FACE_RULE).filter(l=>GN(l.style.getPropertyValue("src")))}async function q3(a,l){if(a.ownerDocument==null)throw new Error("Provided element is not within a Document");const r=wn(a.ownerDocument.styleSheets),c=await F3(r,l);return H3(c)}function YN(a){return a.trim().replace(/["']/g,"")}function V3(a){const l=new Set;function r(c){(c.style.fontFamily||getComputedStyle(c).fontFamily).split(",").forEach(m=>{l.add(YN(m))}),Array.from(c.children).forEach(m=>{m instanceof HTMLElement&&r(m)})}return r(a),l}async function G3(a,l){const r=await q3(a,l),c=V3(a);return(await Promise.all(r.filter(m=>c.has(YN(m.style.fontFamily))).map(m=>{const h=m.parentStyleSheet?m.parentStyleSheet.href:null;return KN(m.cssText,h,l)}))).join(` -`)}async function K3(a,l){const r=l.fontEmbedCSS!=null?l.fontEmbedCSS:l.skipFonts?null:await G3(a,l);if(r){const c=document.createElement("style"),d=document.createTextNode(r);c.appendChild(d),a.firstChild?a.insertBefore(c,a.firstChild):a.appendChild(c)}}async function Q3(a,l={}){const{width:r,height:c}=FN(a,l),d=await jd(a,l,!0);return await K3(d,l),await QN(d,l),P3(d,l),await u3(d,r,c)}async function Y3(a,l={}){const{width:r,height:c}=FN(a,l),d=await Q3(a,l),m=await sd(d),h=document.createElement("canvas"),f=h.getContext("2d"),p=l.pixelRatio||c3(),g=l.canvasWidth||r,N=l.canvasHeight||c;return h.width=g*p,h.height=N*p,l.skipAutoScale||o3(h),h.style.width=`${g}`,h.style.height=`${N}`,l.backgroundColor&&(f.fillStyle=l.backgroundColor,f.fillRect(0,0,h.width,h.height)),f.drawImage(m,0,0,h.width,h.height),h}async function J3(a,l={}){return(await Y3(a,l)).toDataURL()}const $o=["#0088FE","#00C49F","#FFBB28","#FF8042","#8884d8","#82ca9d"];function X3(a){return a>=8760?"相当于全年无休,7x24小时在线!":a>=5e3?"相当于一位全职员工的年工作时长":a>=2e3?"相当于看完了 1000 部电影":a>=1e3?"相当于环球飞行 80 次":a>=500?"相当于读完了 100 本书":a>=100?"相当于马拉松跑了 25 次":"虽然不多,但每一刻都很珍贵"}function Z3(a){return a>=1e3?"夜深人静时的知心好友":a>=500?"午夜场的常客":a>=100?"偶尔熬夜的小伙伴":a>=50?"深夜有时也会陪你聊聊":"早睡早起,健康作息"}function W3(a){const l=a/1e6;return l>=100?"思考量堪比一座图书馆":l>=50?"相当于写了一部百科全书":l>=10?"脑细胞估计消耗了不少":l>=1?"也算是费了一番脑筋":"轻轻松松,游刃有余"}function e5(a){return a>=1e3?"这钱够吃一年的泡面了":a>=500?"相当于买了一台游戏机":a>=100?"够请大家喝几杯奶茶":a>=50?"一顿火锅的钱":a>=10?"几杯咖啡的价格":"省钱小能手"}function s5(a){return a>=80?"沉默是金,惜字如金":a>=60?"话不多但句句到位":a>=40?"该说的时候才开口":a>=20?"能聊的都聊了":"话痨本痨,有问必答"}function t5(a){return a>=1e4?"眼睛都快看花了":a>=5e3?"堪比专业摄影师的阅片量":a>=1e3?"看图小达人":a>=500?"图片鉴赏家":a>=100?"偶尔欣赏一下美图":"图片?有空再看"}function a5(a){return a>=500?"在不断的纠正中成长":a>=200?"学习永无止境":a>=100?"虚心接受,积极改正":a>=50?"偶尔也会犯错":a>=10?"表现还算不错":"完美表达,无需纠正"}function l5(a){return a>=1?"这次思考的价值堪比一顿大餐!":a>=.5?"为了这个问题,我可是认真思考了!":a>=.1?"下了点功夫,值得的!":a>=.01?"花了点小钱,但很值得":"小小思考,不足挂齿"}function n5(a,l){return a>=100?"这句话简直是万能钥匙!":a>=50?"百试不爽的经典回复":a>=20?`${l}的口头禅`:a>=10?"常用语录之一":"偶尔用用的小确幸"}function r5(a,l){return a?l>=1e3?"深夜的守护者,黑暗中的光芒":l>=500?"月亮是我的好朋友":l>=100?"越夜越精神,夜晚才是主场":"偶尔熬夜,享受宁静时光":l<=10?"作息规律,健康生活的典范":l<=50?"早睡早起,偶尔也会熬个夜":"虽然是早起鸟,但也会守候深夜"}function i5(a){return a>=1e3?"忙到飞起,键盘都要冒烟了":a>=500?"这天简直是话痨附体":a>=200?"社交达人上线":a>=100?"比平时活跃不少":a>=50?"小忙一下":"还算轻松的一天"}function c5(){const[a]=u.useState(2025),[l,r]=u.useState(null),[c,d]=u.useState(!0),[m,h]=u.useState(!1),[f,p]=u.useState(null),g=u.useRef(null),{toast:N}=nt(),j=u.useCallback(async()=>{try{d(!0),p(null);const y=await a3(a);r(y)}catch(y){p(y instanceof Error?y:new Error("获取年度报告失败"))}finally{d(!1)}},[a]),b=u.useCallback(async()=>{if(!(!g.current||!l)){h(!0),N({title:"正在生成图片",description:"请稍候..."});try{const y=g.current,w=getComputedStyle(document.documentElement),z=w.getPropertyValue("--background").trim()?`hsl(${w.getPropertyValue("--background").trim()})`:document.documentElement.classList.contains("dark")?"#0a0a0a":"#ffffff",M=y.style.width,S=y.style.maxWidth;y.style.width="1024px",y.style.maxWidth="1024px";const F=await J3(y,{quality:1,pixelRatio:2,backgroundColor:z,cacheBust:!0,filter:C=>!(C instanceof HTMLElement&&C.hasAttribute("data-export-btn"))});y.style.width=M,y.style.maxWidth=S;const E=document.createElement("a");E.download=`${l.bot_name}_${l.year}_年度总结.png`,E.href=F,E.click(),N({title:"导出成功",description:"年度报告已保存为图片"})}catch(y){console.error("导出图片失败:",y),N({title:"导出失败",description:"请重试",variant:"destructive"})}finally{h(!1)}}},[l,N]);return u.useEffect(()=>{j()},[j]),c?e.jsx(o5,{}):f?e.jsxs("div",{className:"flex h-screen items-center justify-center text-red-500",children:["获取年度报告失败: ",f.message]}):l?e.jsx(ts,{className:"h-[calc(100vh-4rem)]",children:e.jsx("div",{className:"min-h-screen bg-gradient-to-b from-background to-muted/50 p-4 md:p-8 print:p-0",ref:g,children:e.jsxs("div",{className:"mx-auto max-w-5xl space-y-8 print:space-y-4",children:[e.jsxs("header",{className:"relative overflow-hidden rounded-3xl bg-primary p-8 text-primary-foreground shadow-2xl print:rounded-none print:shadow-none",children:[e.jsx("div",{className:"absolute right-4 top-4 z-20 print:hidden","data-export-btn":!0,children:e.jsx(_,{variant:"secondary",size:"sm",onClick:b,disabled:m,className:"gap-2 bg-white/20 hover:bg-white/30 text-white border-white/30",children:m?e.jsxs(e.Fragment,{children:[e.jsx(Fs,{className:"h-4 w-4 animate-spin"}),"导出中..."]}):e.jsxs(e.Fragment,{children:[e.jsx(na,{className:"h-4 w-4"}),"保存图片"]})})}),e.jsxs("div",{className:"relative z-10 flex flex-col items-center text-center",children:[e.jsx(Yn,{className:"mb-4 h-16 w-16 animate-bounce"}),e.jsxs("h1",{className:"text-4xl font-bold tracking-tighter sm:text-6xl",children:[l.bot_name," ",l.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(Ko,{className:"h-4 w-4"}),e.jsxs("span",{children:["生成时间: ",l.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(da,{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(La,{title:"年度在线时长",value:`${l.time_footprint.total_online_hours} 小时`,description:X3(l.time_footprint.total_online_hours),icon:e.jsx(da,{className:"h-4 w-4"})}),e.jsx(La,{title:"最忙碌的一天",value:l.time_footprint.busiest_day||"N/A",description:i5(l.time_footprint.busiest_day_count),icon:e.jsx(Ko,{className:"h-4 w-4"})}),e.jsx(La,{title:"深夜互动 (0-4点)",value:`${l.time_footprint.midnight_chat_count} 次`,description:Z3(l.time_footprint.midnight_chat_count),icon:e.jsx(tc,{className:"h-4 w-4"})}),e.jsx(La,{title:"作息属性",value:l.time_footprint.is_night_owl?"夜猫子":"早起鸟",description:r5(l.time_footprint.is_night_owl,l.time_footprint.midnight_chat_count),icon:l.time_footprint.is_night_owl?e.jsx(tc,{className:"h-4 w-4"}):e.jsx(ix,{className:"h-4 w-4"})})]}),e.jsxs(Te,{className:"overflow-hidden",children:[e.jsxs(Oe,{children:[e.jsx(Ue,{children:"24小时活跃时钟"}),e.jsxs(Ns,{children:[l.bot_name,"在一天中各个时段的活跃程度"]})]}),e.jsx(ze,{className:"h-[300px]",children:e.jsx(Uj,{width:"100%",height:"100%",children:e.jsxs(Bo,{data:l.time_footprint.hourly_distribution.map((y,w)=>({hour:`${w}点`,count:y})),children:[e.jsx(Ji,{strokeDasharray:"3 3",vertical:!1}),e.jsx(Xi,{dataKey:"hour"}),e.jsx(Gr,{}),e.jsx($j,{contentStyle:{borderRadius:"8px",border:"none",boxShadow:"0 4px 12px rgba(0,0,0,0.1)"},cursor:{fill:"transparent"}}),e.jsx(Zi,{dataKey:"count",fill:"hsl(var(--primary))",radius:[4,4,0,0]})]})})})]}),l.time_footprint.first_message_time&&e.jsx(Te,{className:"bg-muted/30 border-dashed",children:e.jsxs(ze,{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:l.time_footprint.first_message_time}),e.jsxs("p",{className:"text-lg",children:[e.jsx("span",{className:"font-semibold text-foreground",children:l.time_footprint.first_message_user})," 说:",e.jsxs("span",{className:"italic text-muted-foreground",children:['"',l.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(oc,{className:"h-8 w-8"}),e.jsx("h2",{children:"社交网络"})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsx(La,{title:"社交圈子",value:`${l.social_network.total_groups} 个群组`,description:`${l.bot_name}加入的群组总数`,icon:e.jsx(oc,{className:"h-4 w-4"})}),e.jsx(La,{title:"被呼叫次数",value:`${l.social_network.at_count+l.social_network.mentioned_count} 次`,description:"我的名字被大家频繁提起",icon:e.jsx(W1,{className:"h-4 w-4"})}),e.jsx(La,{title:"最长情陪伴",value:l.social_network.longest_companion_user||"N/A",description:`始终都在,已陪伴 ${l.social_network.longest_companion_days} 天`,icon:e.jsx(ei,{className:"h-4 w-4 text-red-500"})})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(Te,{children:[e.jsx(Oe,{children:e.jsx(Ue,{children:"话痨群组 TOP5"})}),e.jsx(ze,{children:e.jsx("div",{className:"space-y-3",children:l.social_network.top_groups.length>0?l.social_network.top_groups.map((y,w)=>e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ce,{variant:w===0?"default":"secondary",className:"h-6 w-6 rounded-full p-0 flex items-center justify-center shrink-0",children:w+1}),e.jsx("span",{className:"font-medium truncate max-w-[120px]",children:y.group_name}),y.is_webui&&e.jsx(Ce,{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:[y.message_count," 条消息"]})]},y.group_id)):e.jsx("div",{className:"text-center text-muted-foreground py-4",children:"暂无数据"})})})]}),e.jsxs(Te,{children:[e.jsx(Oe,{children:e.jsx(Ue,{children:"年度最佳损友 TOP5"})}),e.jsx(ze,{children:e.jsx("div",{className:"space-y-3",children:l.social_network.top_users.length>0?l.social_network.top_users.map((y,w)=>e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ce,{variant:w===0?"default":"secondary",className:"h-6 w-6 rounded-full p-0 flex items-center justify-center shrink-0",children:w+1}),e.jsx("span",{className:"font-medium truncate max-w-[120px]",children:y.user_nickname}),y.is_webui&&e.jsx(Ce,{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:[y.message_count," 次互动"]})]},y.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(hx,{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(La,{title:"年度 Token 消耗",value:(l.brain_power.total_tokens/1e6).toFixed(2)+" M",description:W3(l.brain_power.total_tokens),icon:e.jsx(sl,{className:"h-4 w-4"})}),e.jsx(La,{title:"年度总花费",value:`$${l.brain_power.total_cost.toFixed(2)}`,description:e5(l.brain_power.total_cost),icon:e.jsx("span",{className:"font-bold",children:"$"})}),e.jsx(La,{title:"高冷指数",value:`${l.brain_power.silence_rate}%`,description:s5(l.brain_power.silence_rate),icon:e.jsx(tc,{className:"h-4 w-4"})}),e.jsx(La,{title:"最高兴趣值",value:l.brain_power.max_interest_value??"N/A",description:l.brain_power.max_interest_time?`出现在 ${l.brain_power.max_interest_time}`:"暂无数据",icon:e.jsx(ei,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(Te,{children:[e.jsx(Oe,{children:e.jsx(Ue,{children:"模型偏好分布"})}),e.jsx(ze,{children:e.jsx("div",{className:"space-y-3",children:l.brain_power.model_distribution.slice(0,5).map((y,w)=>{const z=l.brain_power.model_distribution[0]?.count||1,M=Math.round(y.count/z*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:y.model}),e.jsxs("span",{className:"text-muted-foreground",children:[y.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:`${M}%`,backgroundColor:$o[w%$o.length]}})})]},y.model)})})})]}),l.brain_power.top_reply_models&&l.brain_power.top_reply_models.length>0&&e.jsxs(Te,{children:[e.jsxs(Oe,{children:[e.jsx(Ue,{children:"最喜欢的回复模型 TOP5"}),e.jsxs(Ns,{children:[l.bot_name,"用来回复消息的模型偏好"]})]}),e.jsx(ze,{children:e.jsx("div",{className:"space-y-3",children:l.brain_power.top_reply_models.map((y,w)=>{const z=l.brain_power.top_reply_models[0]?.count||1,M=Math.round(y.count/z*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:y.model}),e.jsxs("span",{className:"text-muted-foreground",children:[y.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:`${M}%`,backgroundColor:$o[w%$o.length]}})})]},y.model)})})})]}),l.brain_power.top_token_consumers&&l.brain_power.top_token_consumers.length>0&&e.jsxs(Te,{children:[e.jsxs(Oe,{children:[e.jsx(Ue,{children:"烧钱大户 TOP3"}),e.jsx(Ns,{children:"谁消耗了最多的 API 额度"})]}),e.jsx(ze,{children:e.jsx("div",{className:"space-y-6",children:l.brain_power.top_token_consumers.map(y=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between text-sm font-medium",children:[e.jsxs("span",{children:["用户 ",y.user_id]}),e.jsxs("span",{children:["$",y.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:`${y.cost/(l.brain_power.top_token_consumers[0]?.cost||1)*100}%`}})})]},y.user_id))})})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(Te,{className:"bg-gradient-to-br from-amber-50 to-orange-50 dark:from-amber-950/20 dark:to-orange-950/20",children:[e.jsx(Oe,{children:e.jsxs(Ue,{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-2xl",children:"💰"}),"最昂贵的一次思考"]})}),e.jsxs(ze,{className:"text-center",children:[e.jsxs("div",{className:"text-4xl font-bold text-amber-600 dark:text-amber-400",children:["$",l.brain_power.most_expensive_cost.toFixed(4)]}),l.brain_power.most_expensive_time&&e.jsxs("p",{className:"mt-2 text-sm text-muted-foreground",children:["发生在 ",l.brain_power.most_expensive_time]}),e.jsx("p",{className:"mt-4 text-sm text-muted-foreground",children:l5(l.brain_power.most_expensive_cost)})]})]}),e.jsxs(Te,{className:"bg-gradient-to-br from-indigo-50 to-blue-50 dark:from-indigo-950/20 dark:to-blue-950/20",children:[e.jsx(Oe,{children:e.jsxs(Ue,{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-2xl",children:"🧠"}),"思考深度"]})}),e.jsxs(ze,{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:l.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:l.brain_power.max_reasoning_length?.toLocaleString()||0}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"最长思考字数"})]})]}),l.brain_power.max_reasoning_time&&e.jsxs("p",{className:"mt-4 text-center text-xs text-muted-foreground",children:["最深沉的思考发生在 ",l.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(rd,{className:"h-8 w-8"}),e.jsx("h2",{children:"个性与表达"})]}),(l.expression_vibe.late_night_reply||l.expression_vibe.favorite_reply)&&e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[l.expression_vibe.late_night_reply&&e.jsxs(Te,{className:"bg-gradient-to-br from-indigo-50 to-violet-50 dark:from-indigo-950/20 dark:to-violet-950/20",children:[e.jsxs(Oe,{children:[e.jsxs(Ue,{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-2xl",children:"🌙"}),"深夜还在回复"]}),e.jsxs(Ns,{children:["凌晨 ",l.expression_vibe.late_night_reply.time,",",l.bot_name,"还在回复..."]})]}),e.jsxs(ze,{className:"text-center",children:[e.jsxs("p",{className:"text-lg italic text-muted-foreground",children:['"',l.expression_vibe.late_night_reply.content,'"']}),e.jsx("p",{className:"mt-4 text-sm text-muted-foreground",children:"是有什么心事吗?"})]})]}),l.expression_vibe.favorite_reply&&e.jsxs(Te,{className:"bg-gradient-to-br from-rose-50 to-pink-50 dark:from-rose-950/20 dark:to-pink-950/20",children:[e.jsxs(Oe,{children:[e.jsxs(Ue,{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-2xl",children:"💬"}),"最喜欢的回复"]}),e.jsxs(Ns,{children:["使用了 ",l.expression_vibe.favorite_reply.count," 次"]})]}),e.jsxs(ze,{className:"text-center",children:[e.jsxs("p",{className:"text-lg font-medium text-primary",children:['"',l.expression_vibe.favorite_reply.content,'"']}),e.jsx("p",{className:"mt-4 text-sm text-muted-foreground",children:n5(l.expression_vibe.favorite_reply.count,l.bot_name)})]})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(Te,{className:"bg-gradient-to-br from-pink-50 to-purple-50 dark:from-pink-950/20 dark:to-purple-950/20",children:[e.jsxs(Oe,{children:[e.jsx(Ue,{children:"使用最多的表情包 TOP3"}),e.jsx(Ns,{children:"年度最爱的表情包们"})]}),e.jsx(ze,{children:l.expression_vibe.top_emojis&&l.expression_vibe.top_emojis.length>0?e.jsx("div",{className:"flex justify-center gap-4",children:l.expression_vibe.top_emojis.slice(0,3).map((y,w)=>e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:`/api/webui/emoji/${y.id}/thumbnail?original=true`,alt:`TOP ${w+1}`,className:"h-24 w-24 rounded-lg object-cover shadow-md transition-transform hover:scale-105"}),e.jsx(Ce,{className:P("absolute -top-2 -right-2",w===0?"bg-yellow-500":w===1?"bg-gray-400":"bg-amber-700"),children:w+1})]}),e.jsxs("p",{className:"mt-2 text-sm text-muted-foreground",children:[y.usage_count," 次"]})]},y.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(Te,{children:[e.jsxs(Oe,{children:[e.jsx(Ue,{children:"印象最深刻的表达风格"}),e.jsxs(Ns,{children:[l.bot_name,"最常使用的表达方式"]})]}),e.jsx(ze,{children:e.jsx("div",{className:"flex flex-wrap gap-2",children:l.expression_vibe.top_expressions.map((y,w)=>e.jsxs(Ce,{variant:"outline",className:P("px-3 py-1 text-sm",w===0&&"border-primary bg-primary/10 text-primary text-base px-4 py-2"),children:[y.style," (",y.count,")"]},y.style))})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(La,{title:"图片鉴赏",value:`${l.expression_vibe.image_processed_count} 张`,description:t5(l.expression_vibe.image_processed_count),icon:e.jsx(xx,{className:"h-4 w-4"})}),e.jsx(La,{title:"成长的足迹",value:`${l.expression_vibe.rejected_expression_count} 次`,description:a5(l.expression_vibe.rejected_expression_count),icon:e.jsx(sl,{className:"h-4 w-4"})})]})]})]}),l.expression_vibe.action_types.length>0&&e.jsxs(Te,{children:[e.jsxs(Oe,{children:[e.jsxs(Ue,{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-2xl",children:"⚡"}),"行动派"]}),e.jsx(Ns,{children:"除了聊天,我还帮大家做了这些事"})]}),e.jsx(ze,{children:e.jsx("div",{className:"flex flex-wrap gap-3",children:l.expression_vibe.action_types.map(y=>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:y.action}),e.jsxs(Ce,{variant:"secondary",children:[y.count," 次"]})]},y.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(e_,{className:"h-8 w-8"}),e.jsx("h2",{children:"趣味成就"})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsxs(Te,{className:"col-span-1 md:col-span-2",children:[e.jsxs(Oe,{children:[e.jsx(Ue,{children:'新学到的"黑话"'}),e.jsxs(Ns,{children:["今年我学会了 ",l.achievements.new_jargon_count," 个新词"]})]}),e.jsx(ze,{children:e.jsx("div",{className:"flex flex-wrap gap-3",children:l.achievements.sample_jargons.map(y=>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:y.content}),e.jsx("div",{className:"text-xs text-muted-foreground mt-1 line-clamp-2 max-w-[200px]",children:y.meaning||"暂无解释"})]},y.content))})})]}),e.jsx(Te,{className:"flex flex-col justify-center items-center bg-primary text-primary-foreground",children:e.jsxs(ze,{className:"flex flex-col items-center justify-center p-6 text-center",children:[e.jsx(Ia,{className:"h-12 w-12 mb-4 opacity-80"}),e.jsx("div",{className:"text-4xl font-bold mb-2",children:l.achievements.total_messages.toLocaleString()}),e.jsx("div",{className:"text-sm opacity-80",children:"年度总消息数"}),e.jsxs("div",{className:"mt-4 text-xs opacity-60",children:["其中回复了 ",l.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 La({title:a,value:l,description:r,icon:c}){return e.jsxs(Te,{children:[e.jsxs(Oe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Ue,{className:"text-sm font-medium",children:a}),e.jsx("div",{className:"text-muted-foreground",children:c})]}),e.jsxs(ze,{children:[e.jsx("div",{className:"text-2xl font-bold",children:l}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r})]})]})}function o5(){return e.jsxs("div",{className:"container mx-auto space-y-8 p-8",children:[e.jsx(ks,{className:"h-64 w-full rounded-3xl"}),e.jsx("div",{className:"grid gap-4 md:grid-cols-4",children:[...Array(4)].map((a,l)=>e.jsx(ks,{className:"h-32 w-full"},l))}),e.jsx(ks,{className:"h-96 w-full"})]})}var vd="DropdownMenu",[d5]=ld(vd,[Oj]),fa=Oj(),[u5,JN]=d5(vd),XN=a=>{const{__scopeDropdownMenu:l,children:r,dir:c,open:d,defaultOpen:m,onOpenChange:h,modal:f=!0}=a,p=fa(l),g=u.useRef(null),[N,j]=ad({prop:d,defaultProp:m??!1,onChange:h,caller:vd});return e.jsx(u5,{scope:l,triggerId:Ym(),triggerRef:g,contentId:Ym(),open:N,onOpenChange:j,onOpenToggle:u.useCallback(()=>j(b=>!b),[j]),modal:f,children:e.jsx(Vw,{...p,open:N,onOpenChange:j,dir:c,modal:f,children:r})})};XN.displayName=vd;var ZN="DropdownMenuTrigger",WN=u.forwardRef((a,l)=>{const{__scopeDropdownMenu:r,disabled:c=!1,...d}=a,m=JN(ZN,r),h=fa(r);return e.jsx(Gw,{asChild:!0,...h,children:e.jsx(ar.button,{type:"button",id:m.triggerId,"aria-haspopup":"menu","aria-expanded":m.open,"aria-controls":m.open?m.contentId:void 0,"data-state":m.open?"open":"closed","data-disabled":c?"":void 0,disabled:c,...d,ref:_1(l,m.triggerRef),onPointerDown:_n(a.onPointerDown,f=>{!c&&f.button===0&&f.ctrlKey===!1&&(m.onOpenToggle(),m.open||f.preventDefault())}),onKeyDown:_n(a.onKeyDown,f=>{c||(["Enter"," "].includes(f.key)&&m.onOpenToggle(),f.key==="ArrowDown"&&m.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(f.key)&&f.preventDefault())})})})});WN.displayName=ZN;var m5="DropdownMenuPortal",eb=a=>{const{__scopeDropdownMenu:l,...r}=a,c=fa(l);return e.jsx(Uw,{...c,...r})};eb.displayName=m5;var sb="DropdownMenuContent",tb=u.forwardRef((a,l)=>{const{__scopeDropdownMenu:r,...c}=a,d=JN(sb,r),m=fa(r),h=u.useRef(!1);return e.jsx($w,{id:d.contentId,"aria-labelledby":d.triggerId,...m,...c,ref:l,onCloseAutoFocus:_n(a.onCloseAutoFocus,f=>{h.current||d.triggerRef.current?.focus(),h.current=!1,f.preventDefault()}),onInteractOutside:_n(a.onInteractOutside,f=>{const p=f.detail.originalEvent,g=p.button===0&&p.ctrlKey===!0,N=p.button===2||g;(!d.modal||N)&&(h.current=!0)}),style:{...a.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});tb.displayName=sb;var x5="DropdownMenuGroup",h5=u.forwardRef((a,l)=>{const{__scopeDropdownMenu:r,...c}=a,d=fa(r);return e.jsx(Kw,{...d,...c,ref:l})});h5.displayName=x5;var f5="DropdownMenuLabel",ab=u.forwardRef((a,l)=>{const{__scopeDropdownMenu:r,...c}=a,d=fa(r);return e.jsx(Hw,{...d,...c,ref:l})});ab.displayName=f5;var p5="DropdownMenuItem",lb=u.forwardRef((a,l)=>{const{__scopeDropdownMenu:r,...c}=a,d=fa(r);return e.jsx(Bw,{...d,...c,ref:l})});lb.displayName=p5;var g5="DropdownMenuCheckboxItem",nb=u.forwardRef((a,l)=>{const{__scopeDropdownMenu:r,...c}=a,d=fa(r);return e.jsx(Iw,{...d,...c,ref:l})});nb.displayName=g5;var j5="DropdownMenuRadioGroup",v5=u.forwardRef((a,l)=>{const{__scopeDropdownMenu:r,...c}=a,d=fa(r);return e.jsx(Qw,{...d,...c,ref:l})});v5.displayName=j5;var N5="DropdownMenuRadioItem",rb=u.forwardRef((a,l)=>{const{__scopeDropdownMenu:r,...c}=a,d=fa(r);return e.jsx(Fw,{...d,...c,ref:l})});rb.displayName=N5;var b5="DropdownMenuItemIndicator",ib=u.forwardRef((a,l)=>{const{__scopeDropdownMenu:r,...c}=a,d=fa(r);return e.jsx(Pw,{...d,...c,ref:l})});ib.displayName=b5;var y5="DropdownMenuSeparator",cb=u.forwardRef((a,l)=>{const{__scopeDropdownMenu:r,...c}=a,d=fa(r);return e.jsx(qw,{...d,...c,ref:l})});cb.displayName=y5;var w5="DropdownMenuArrow",_5=u.forwardRef((a,l)=>{const{__scopeDropdownMenu:r,...c}=a,d=fa(r);return e.jsx(Yw,{...d,...c,ref:l})});_5.displayName=w5;var S5="DropdownMenuSubTrigger",ob=u.forwardRef((a,l)=>{const{__scopeDropdownMenu:r,...c}=a,d=fa(r);return e.jsx(Ow,{...d,...c,ref:l})});ob.displayName=S5;var k5="DropdownMenuSubContent",db=u.forwardRef((a,l)=>{const{__scopeDropdownMenu:r,...c}=a,d=fa(r);return e.jsx(Lw,{...d,...c,ref:l,style:{...a.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});db.displayName=k5;var C5=XN,T5=WN,E5=eb,ub=tb,mb=ab,xb=lb,hb=nb,fb=rb,pb=ib,gb=cb,jb=ob,vb=db;const M5=C5,A5=T5,z5=u.forwardRef(({className:a,inset:l,children:r,...c},d)=>e.jsxs(jb,{ref:d,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",l&&"pl-8",a),...c,children:[r,e.jsx(ra,{className:"ml-auto h-4 w-4"})]}));z5.displayName=jb.displayName;const R5=u.forwardRef(({className:a,...l},r)=>e.jsx(vb,{ref:r,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",a),...l}));R5.displayName=vb.displayName;const Nb=u.forwardRef(({className:a,sideOffset:l=4,...r},c)=>e.jsx(E5,{children:e.jsx(ub,{ref:c,sideOffset:l,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",a),...r})}));Nb.displayName=ub.displayName;const bb=u.forwardRef(({className:a,inset:l,...r},c)=>e.jsx(xb,{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",l&&"pl-8",a),...r}));bb.displayName=xb.displayName;const D5=u.forwardRef(({className:a,children:l,checked:r,...c},d)=>e.jsxs(hb,{ref:d,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",a),checked:r,...c,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(pb,{children:e.jsx(Ot,{className:"h-4 w-4"})})}),l]}));D5.displayName=hb.displayName;const O5=u.forwardRef(({className:a,children:l,...r},c)=>e.jsxs(fb,{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",a),...r,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(pb,{children:e.jsx(Vo,{className:"h-2 w-2 fill-current"})})}),l]}));O5.displayName=fb.displayName;const L5=u.forwardRef(({className:a,inset:l,...r},c)=>e.jsx(mb,{ref:c,className:P("px-2 py-1.5 text-sm font-semibold",l&&"pl-8",a),...r}));L5.displayName=mb.displayName;const U5=u.forwardRef(({className:a,...l},r)=>e.jsx(gb,{ref:r,className:P("-mx-1 my-1 h-px bg-muted",a),...l}));U5.displayName=gb.displayName;const Qm=[{value:"created_at",label:"最新发布",icon:da},{value:"downloads",label:"下载最多",icon:na},{value:"likes",label:"最受欢迎",icon:ei}];function $5(){const a=ha(),[l,r]=u.useState([]),[c,d]=u.useState(!0),[m,h]=u.useState(""),[f,p]=u.useState("downloads"),[g,N]=u.useState(1),[j,b]=u.useState(1),[y,w]=u.useState(0),[z,M]=u.useState(new Set),[S,F]=u.useState(new Set),E=cN(),C=u.useCallback(async()=>{d(!0);try{const L=await m4({status:"approved",page:g,page_size:12,search:m||void 0,sort_by:f,sort_order:"desc"});r(L.packs),b(L.total_pages),w(L.total);const me=new Set;for(const Ne of L.packs)await iN(Ne.id,E)&&me.add(Ne.id);M(me)}catch(L){console.error("加载 Pack 列表失败:",L),aa({title:"加载 Pack 列表失败",variant:"destructive"})}finally{d(!1)}},[g,m,f,E]);u.useEffect(()=>{C()},[C]);const R=L=>{L.preventDefault(),N(1),C()},H=async L=>{if(!S.has(L)){F(me=>new Set(me).add(L));try{const me=await rN(L,E);M(Ne=>{const je=new Set(Ne);return me.liked?je.add(L):je.delete(L),je}),r(Ne=>Ne.map(je=>je.id===L?{...je,likes:me.likes}:je))}catch(me){console.error("点赞失败:",me),aa({title:"点赞失败",variant:"destructive"})}finally{F(me=>{const Ne=new Set(me);return Ne.delete(L),Ne})}}},O=L=>{a({to:"/config/pack-market/$packId",params:{packId:L}})},X=Qm.find(L=>L.value===f)||Qm[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(xa,{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(ts,{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:R,className:"flex-1 min-w-[200px] max-w-md",children:e.jsxs("div",{className:"relative",children:[e.jsx($t,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(ne,{placeholder:"搜索模板名称、描述...",value:m,onChange:L=>h(L.target.value),className:"pl-10"})]})}),e.jsxs(M5,{children:[e.jsx(A5,{asChild:!0,children:e.jsxs(_,{variant:"outline",className:"min-w-[140px] gap-2",children:[e.jsx(s_,{className:"w-4 h-4"}),X.label,e.jsx(Ba,{className:"w-4 h-4 ml-auto"})]})}),e.jsx(Nb,{align:"end",children:Qm.map(L=>e.jsxs(bb,{onClick:()=>{p(L.value),N(1)},children:[e.jsx(L.icon,{className:"w-4 h-4 mr-2"}),L.label]},L.value))})]})]}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:["共找到 ",e.jsx("span",{className:"font-medium text-foreground",children:y})," 个模板"]}),c?e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:Array.from({length:6}).map((L,me)=>e.jsxs(Te,{children:[e.jsxs(Oe,{children:[e.jsx(ks,{className:"h-6 w-3/4"}),e.jsx(ks,{className:"h-4 w-full mt-2"})]}),e.jsx(ze,{children:e.jsx(ks,{className:"h-20 w-full"})}),e.jsx(od,{children:e.jsx(ks,{className:"h-9 w-full"})})]},me))}):l.length===0?e.jsx(Te,{className:"py-12",children:e.jsxs(ze,{className:"text-center text-muted-foreground",children:[e.jsx(xa,{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:l.map(L=>e.jsx(B5,{pack:L,liked:z.has(L.id),liking:S.has(L.id),onLike:()=>H(L.id),onView:()=>O(L.id)},L.id))}),j>1&&e.jsx(fx,{children:e.jsxs(px,{children:[e.jsx(Xn,{children:e.jsx($v,{onClick:()=>N(L=>Math.max(1,L-1)),className:g===1?"pointer-events-none opacity-50":"cursor-pointer"})}),Array.from({length:j},(L,me)=>me+1).filter(L=>L===1||L===j||Math.abs(L-g)<=1).map((L,me,Ne)=>{const je=me>0&&L-Ne[me-1]>1;return e.jsxs(Xn,{children:[je&&e.jsx("span",{className:"px-2",children:"..."}),e.jsx(jc,{onClick:()=>N(L),isActive:L===g,className:"cursor-pointer",children:L})]},L)}),e.jsx(Xn,{children:e.jsx(Bv,{onClick:()=>N(L=>Math.min(j,L+1)),className:g===j?"pointer-events-none opacity-50":"cursor-pointer"})})]})})]})})]})}function B5({pack:a,liked:l,liking:r,onLike:c,onView:d}){const m=h=>new Date(h).toLocaleDateString("zh-CN",{year:"numeric",month:"short",day:"numeric"});return e.jsxs(Te,{className:"flex flex-col hover:shadow-md transition-shadow",children:[e.jsxs(Oe,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsx(Ue,{className:"text-lg line-clamp-1",children:a.name}),e.jsxs(Ce,{variant:"secondary",className:"text-xs",children:["v",a.version]})]}),e.jsx(Ns,{className:"line-clamp-2 min-h-[40px]",children:a.description})]}),e.jsxs(ze,{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(Fl,{className:"w-3.5 h-3.5"}),a.author]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(da,{className:"w-3.5 h-3.5"}),m(a.created_at)]})]}),e.jsxs("div",{className:"flex gap-4 text-sm",children:[e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground",title:"提供商数量",children:[e.jsx(Hl,{className:"w-3.5 h-3.5"}),a.provider_count]}),e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground",title:"模型数量",children:[e.jsx(Wn,{className:"w-3.5 h-3.5"}),a.model_count]}),e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground",title:"任务配置数",children:[e.jsx(er,{className:"w-3.5 h-3.5"}),a.task_count]})]}),a.tags&&a.tags.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1",children:[a.tags.slice(0,3).map(h=>e.jsxs(Ce,{variant:"outline",className:"text-xs",children:[e.jsx(cd,{className:"w-2.5 h-2.5 mr-1"}),h]},h)),a.tags.length>3&&e.jsxs(Ce,{variant:"outline",className:"text-xs",children:["+",a.tags.length-3]})]})]}),e.jsx(od,{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(na,{className:"w-4 h-4"}),a.downloads]}),e.jsxs("button",{onClick:h=>{h.stopPropagation(),c()},disabled:r,className:`flex items-center gap-1 transition-colors ${l?"text-red-500":"hover:text-red-500"} ${r?"opacity-50":""}`,children:[e.jsx(ei,{className:`w-4 h-4 ${l?"fill-current":""}`}),a.likes]})]}),e.jsx(_,{size:"sm",onClick:d,children:"查看详情"})]})})]})}var ul="Accordion",I5=["Home","End","ArrowDown","ArrowUp","ArrowLeft","ArrowRight"],[Lx,P5,F5]=S1(ul),[Nd]=ld(ul,[F5,Lj]),Ux=Lj(),yb=Bs.forwardRef((a,l)=>{const{type:r,...c}=a,d=c,m=c;return e.jsx(Lx.Provider,{scope:a.__scopeAccordion,children:r==="multiple"?e.jsx(G5,{...m,ref:l}):e.jsx(V5,{...d,ref:l})})});yb.displayName=ul;var[wb,H5]=Nd(ul),[_b,q5]=Nd(ul,{collapsible:!1}),V5=Bs.forwardRef((a,l)=>{const{value:r,defaultValue:c,onValueChange:d=()=>{},collapsible:m=!1,...h}=a,[f,p]=ad({prop:r,defaultProp:c??"",onChange:d,caller:ul});return e.jsx(wb,{scope:a.__scopeAccordion,value:Bs.useMemo(()=>f?[f]:[],[f]),onItemOpen:p,onItemClose:Bs.useCallback(()=>m&&p(""),[m,p]),children:e.jsx(_b,{scope:a.__scopeAccordion,collapsible:m,children:e.jsx(Sb,{...h,ref:l})})})}),G5=Bs.forwardRef((a,l)=>{const{value:r,defaultValue:c,onValueChange:d=()=>{},...m}=a,[h,f]=ad({prop:r,defaultProp:c??[],onChange:d,caller:ul}),p=Bs.useCallback(N=>f((j=[])=>[...j,N]),[f]),g=Bs.useCallback(N=>f((j=[])=>j.filter(b=>b!==N)),[f]);return e.jsx(wb,{scope:a.__scopeAccordion,value:h,onItemOpen:p,onItemClose:g,children:e.jsx(_b,{scope:a.__scopeAccordion,collapsible:!0,children:e.jsx(Sb,{...m,ref:l})})})}),[K5,bd]=Nd(ul),Sb=Bs.forwardRef((a,l)=>{const{__scopeAccordion:r,disabled:c,dir:d,orientation:m="vertical",...h}=a,f=Bs.useRef(null),p=nd(f,l),g=P5(r),j=Wj(d)==="ltr",b=_n(a.onKeyDown,y=>{if(!I5.includes(y.key))return;const w=y.target,z=g().filter(X=>!X.ref.current?.disabled),M=z.findIndex(X=>X.ref.current===w),S=z.length;if(M===-1)return;y.preventDefault();let F=M;const E=0,C=S-1,R=()=>{F=M+1,F>C&&(F=E)},H=()=>{F=M-1,F{const{__scopeAccordion:r,value:c,...d}=a,m=bd(td,r),h=H5(td,r),f=Ux(r),p=Ym(),g=c&&h.value.includes(c)||!1,N=m.disabled||a.disabled;return e.jsx(Q5,{scope:r,open:g,disabled:N,triggerId:p,children:e.jsx(Mj,{"data-orientation":m.orientation,"data-state":zb(g),...f,...d,ref:l,disabled:N,open:g,onOpenChange:j=>{j?h.onItemOpen(c):h.onItemClose(c)}})})});kb.displayName=td;var Cb="AccordionHeader",Tb=Bs.forwardRef((a,l)=>{const{__scopeAccordion:r,...c}=a,d=bd(ul,r),m=$x(Cb,r);return e.jsx(ar.h3,{"data-orientation":d.orientation,"data-state":zb(m.open),"data-disabled":m.disabled?"":void 0,...c,ref:l})});Tb.displayName=Cb;var lx="AccordionTrigger",Eb=Bs.forwardRef((a,l)=>{const{__scopeAccordion:r,...c}=a,d=bd(ul,r),m=$x(lx,r),h=q5(lx,r),f=Ux(r);return e.jsx(Lx.ItemSlot,{scope:r,children:e.jsx(Jw,{"aria-disabled":m.open&&!h.collapsible||void 0,"data-orientation":d.orientation,id:m.triggerId,...f,...c,ref:l})})});Eb.displayName=lx;var Mb="AccordionContent",Ab=Bs.forwardRef((a,l)=>{const{__scopeAccordion:r,...c}=a,d=bd(ul,r),m=$x(Mb,r),h=Ux(r);return e.jsx(Xw,{role:"region","aria-labelledby":m.triggerId,"data-orientation":d.orientation,...h,...c,ref:l,style:{"--radix-accordion-content-height":"var(--radix-collapsible-content-height)","--radix-accordion-content-width":"var(--radix-collapsible-content-width)",...a.style}})});Ab.displayName=Mb;function zb(a){return a?"open":"closed"}var Y5=yb,J5=kb,X5=Tb,Rb=Eb,Db=Ab;const Z5=Y5,Ob=u.forwardRef(({className:a,...l},r)=>e.jsx(J5,{ref:r,className:P("border-b",a),...l}));Ob.displayName="AccordionItem";const Lb=u.forwardRef(({className:a,children:l,...r},c)=>e.jsx(X5,{className:"flex",children:e.jsxs(Rb,{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",a),...r,children:[l,e.jsx(Ba,{className:"h-4 w-4 shrink-0 transition-transform duration-200"})]})}));Lb.displayName=Rb.displayName;const Ub=u.forwardRef(({className:a,children:l,...r},c)=>e.jsx(Db,{ref:c,className:"overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down",...r,children:e.jsx("div",{className:P("pb-4 pt-0",a),children:l})}));Ub.displayName=Db.displayName;const W5={utils:"通用工具",utils_small:"轻量工具",tool_use:"工具调用",replyer:"回复生成",planner:"规划推理",vlm:"视觉模型",voice:"语音处理",embedding:"向量嵌入",lpmm_entity_extract:"实体提取",lpmm_rdf_build:"RDF构建",lpmm_qa:"问答模型"};function eT(){const{packId:a}=Pb.useParams(),l=ha(),[r,c]=u.useState(null),[d,m]=u.useState(!0),[h,f]=u.useState(!1),[p,g]=u.useState(!1),[N,j]=u.useState(!1),[b,y]=u.useState(1),[w,z]=u.useState(null),[M,S]=u.useState(!1),[F,E]=u.useState(!1),[C,R]=u.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,O]=u.useState({}),[X,L]=u.useState({}),me=cN(),Ne=u.useCallback(async()=>{if(a){m(!0);try{const D=await x4(a);c(D);const Q=await iN(a,me);f(Q)}catch(D){console.error("加载 Pack 失败:",D),aa({title:"加载模板失败",variant:"destructive"})}finally{m(!1)}}},[a,me]);u.useEffect(()=>{Ne()},[Ne]);const je=async()=>{if(!(!a||p)){g(!0);try{const D=await rN(a,me);f(D.liked),r&&c({...r,likes:D.likes})}catch(D){console.error("点赞失败:",D),aa({title:"点赞失败",variant:"destructive"})}finally{g(!1)}}},ce=async()=>{if(r){j(!0),y(1),S(!0);try{const D=await p4(r);z(D);const Q={};for(const ue of D.existing_providers)Q[ue.pack_provider.name]=ue.local_providers[0].name;O(Q);const B={};for(const ue of D.new_providers)B[ue.name]="";L(B)}catch(D){console.error("检测冲突失败:",D),aa({title:"检测配置冲突失败",variant:"destructive"}),j(!1)}finally{S(!1)}}},ge=async()=>{if(r){if(C.apply_providers&&w){for(const D of w.new_providers)if(!X[D.name]){aa({title:`请填写提供商 "${D.name}" 的 API Key`,variant:"destructive"});return}}E(!0);try{await g4(r,C,H,X),await f4(r.id,me),c({...r,downloads:r.downloads+1}),aa({title:"配置模板应用成功!"}),j(!1)}catch(D){console.error("应用 Pack 失败:",D),aa({title:D instanceof Error?D.message:"应用配置失败",variant:"destructive"})}finally{E(!1)}}},pe=D=>new Date(D).toLocaleDateString("zh-CN",{year:"numeric",month:"long",day:"numeric"});return d?e.jsx(tT,{}):r?e.jsx("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:e.jsx(ts,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsxs(_,{variant:"ghost",size:"sm",onClick:()=>l({to:"/config/pack-market"}),className:"gap-2",children:[e.jsx($a,{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(xa,{className:"w-10 h-10 text-primary mt-1"}),e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold flex items-center gap-2",children:[r.name,e.jsxs(Ce,{variant:"secondary",children:["v",r.version]})]}),e.jsx("p",{className:"text-muted-foreground mt-1",children:r.description})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-4 text-sm text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Fl,{className:"w-4 h-4"}),r.author]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(da,{className:"w-4 h-4"}),pe(r.created_at)]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(na,{className:"w-4 h-4"}),r.downloads," 次下载"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ei,{className:`w-4 h-4 ${h?"fill-red-500 text-red-500":""}`}),r.likes," 赞"]})]}),r.tags&&r.tags.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2",children:r.tags.map(D=>e.jsxs(Ce,{variant:"outline",children:[e.jsx(cd,{className:"w-3 h-3 mr-1"}),D]},D))})]}),e.jsxs("div",{className:"flex flex-col gap-2 min-w-[160px]",children:[e.jsxs(_,{size:"lg",onClick:ce,children:[e.jsx(na,{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(ei,{className:`w-4 h-4 mr-2 ${h?"fill-current":""}`}),h?"已点赞":"点赞"]})]})]}),e.jsx(la,{}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsx(Te,{children:e.jsxs(ze,{className:"flex items-center gap-3 py-4",children:[e.jsx(Hl,{className:"w-8 h-8 text-blue-500 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:r.providers.length}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"API 提供商"})]})]})}),e.jsx(Te,{children:e.jsxs(ze,{className:"flex items-center gap-3 py-4",children:[e.jsx(Wn,{className:"w-8 h-8 text-green-500 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:r.models.length}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"模型配置"})]})]})}),e.jsx(Te,{children:e.jsxs(ze,{className:"flex items-center gap-3 py-4",children:[e.jsx(er,{className:"w-8 h-8 text-purple-500 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:Object.keys(r.task_config).length}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"任务配置"})]})]})})]}),e.jsxs(Jt,{defaultValue:"providers",className:"space-y-4",children:[e.jsxs(Gt,{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(Hl,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"提供商"}),e.jsx("span",{className:"sm:hidden",children:"提供商"}),e.jsxs("span",{className:"hidden sm:inline",children:["(",r.providers.length,")"]})]}),e.jsxs(Xe,{value:"models",className:"gap-1 sm:gap-2",children:[e.jsx(Wn,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"模型"}),e.jsx("span",{className:"sm:hidden",children:"模型"}),e.jsxs("span",{className:"hidden sm:inline",children:["(",r.models.length,")"]})]}),e.jsxs(Xe,{value:"tasks",className:"gap-1 sm:gap-2",children:[e.jsx(er,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"任务配置"}),e.jsx("span",{className:"sm:hidden",children:"任务"}),e.jsxs("span",{className:"hidden sm:inline",children:["(",Object.keys(r.task_config).length,")"]})]})]}),e.jsx(Ss,{value:"providers",children:e.jsxs(Te,{children:[e.jsxs(Oe,{children:[e.jsx(Ue,{children:"API 提供商"}),e.jsx(Ns,{children:"模板中包含的 API 提供商配置(不含 API Key)"})]}),e.jsx(ze,{children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(ql,{children:[e.jsx(Vl,{children:e.jsxs(_t,{children:[e.jsx(ns,{children:"名称"}),e.jsx(ns,{children:"Base URL"}),e.jsx(ns,{children:"类型"})]})}),e.jsx(Gl,{children:r.providers.map(D=>e.jsxs(_t,{children:[e.jsx(Ze,{className:"font-medium whitespace-nowrap",children:D.name}),e.jsx(Ze,{className:"text-muted-foreground font-mono text-sm max-w-[200px] truncate",children:D.base_url}),e.jsx(Ze,{children:e.jsx(Ce,{variant:"outline",children:D.client_type})})]},D.name))})]})})})]})}),e.jsx(Ss,{value:"models",children:e.jsxs(Te,{children:[e.jsxs(Oe,{children:[e.jsx(Ue,{children:"模型配置"}),e.jsx(Ns,{children:"模板中包含的模型配置"})]}),e.jsx(ze,{children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(ql,{children:[e.jsx(Vl,{children:e.jsxs(_t,{children:[e.jsx(ns,{children:"模型名称"}),e.jsx(ns,{children:"标识符"}),e.jsx(ns,{children:"提供商"}),e.jsx(ns,{className:"text-right",children:"价格 (入/出)"})]})}),e.jsx(Gl,{children:r.models.map(D=>e.jsxs(_t,{children:[e.jsx(Ze,{className:"font-medium whitespace-nowrap",children:D.name}),e.jsx(Ze,{className:"text-muted-foreground font-mono text-sm max-w-[150px] truncate",children:D.model_identifier}),e.jsx(Ze,{className:"whitespace-nowrap",children:D.api_provider}),e.jsxs(Ze,{className:"text-right text-muted-foreground whitespace-nowrap",children:["¥",D.price_in," / ¥",D.price_out]})]},D.name))})]})})})]})}),e.jsx(Ss,{value:"tasks",children:e.jsxs(Te,{children:[e.jsxs(Oe,{children:[e.jsx(Ue,{children:"任务配置"}),e.jsx(Ns,{children:"模板中各任务类型的模型分配"})]}),e.jsx(ze,{children:e.jsx(Z5,{type:"multiple",className:"w-full",children:Object.entries(r.task_config).map(([D,Q])=>e.jsxs(Ob,{value:D,children:[e.jsx(Lb,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Sn,{className:"w-4 h-4"}),W5[D]||D,e.jsxs(Ce,{variant:"secondary",className:"ml-2",children:[Q.model_list.length," 个模型"]})]})}),e.jsx(Ub,{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:Q.model_list.map(B=>e.jsx(Ce,{variant:"outline",children:B},B))}),Q.temperature!==void 0&&e.jsxs("div",{className:"text-sm",children:["Temperature: ",e.jsx("span",{className:"font-mono",children:Q.temperature})]}),Q.max_tokens!==void 0&&e.jsxs("div",{className:"text-sm",children:["Max Tokens: ",e.jsx("span",{className:"font-mono",children:Q.max_tokens})]})]})})]},D))})})]})})]}),e.jsx(sT,{open:N,onOpenChange:j,pack:r,step:b,setStep:y,conflicts:w,detectingConflicts:M,applying:F,options:C,setOptions:R,_providerMapping:H,_setProviderMapping:O,newProviderApiKeys:X,setNewProviderApiKeys:L,onApply:ge})]})})}):e.jsxs("div",{className:"text-center py-12",children:[e.jsx(xa,{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:()=>l({to:"/config/pack-market"}),children:[e.jsx($a,{className:"w-4 h-4 mr-2"}),"返回市场"]})]})}function sT({open:a,onOpenChange:l,pack:r,step:c,setStep:d,conflicts:m,detectingConflicts:h,applying:f,options:p,setOptions:g,_providerMapping:N,_setProviderMapping:j,newProviderApiKeys:b,setNewProviderApiKeys:y,onApply:w}){return e.jsx(Qs,{open:a,onOpenChange:l,children:e.jsxs(Hs,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(qs,{children:[e.jsxs(Vs,{className:"flex items-center gap-2",children:[e.jsx(xa,{className:"w-5 h-5"}),"应用配置模板"]}),e.jsxs(at,{children:["步骤 ",c," / ",3,":",c===1&&"选择要应用的内容",c===2&&"配置提供商映射",c===3&&"确认并应用"]})]}),h?e.jsxs("div",{className:"py-8 text-center",children:[e.jsx(Fs,{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(tt,{id:"apply_providers",checked:p.apply_providers,onCheckedChange:M=>g({...p,apply_providers:M})}),e.jsxs(T,{htmlFor:"apply_providers",className:"flex items-center gap-2",children:[e.jsx(Hl,{className:"w-4 h-4"}),"应用提供商配置 (",r.providers.length," 个)"]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(tt,{id:"apply_models",checked:p.apply_models,onCheckedChange:M=>g({...p,apply_models:M})}),e.jsxs(T,{htmlFor:"apply_models",className:"flex items-center gap-2",children:[e.jsx(Wn,{className:"w-4 h-4"}),"应用模型配置 (",r.models.length," 个)"]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(tt,{id:"apply_task_config",checked:p.apply_task_config,onCheckedChange:M=>g({...p,apply_task_config:M})}),e.jsxs(T,{htmlFor:"apply_task_config",className:"flex items-center gap-2",children:[e.jsx(er,{className:"w-4 h-4"}),"应用任务配置 (",Object.keys(r.task_config).length," 个)"]})]})]}),p.apply_task_config&&e.jsxs("div",{className:"pl-6 space-y-2 border-l-2 border-muted",children:[e.jsx(T,{className:"text-sm font-medium",children:"任务配置应用模式"}),e.jsxs(Rx,{value:p.task_mode,onValueChange:M=>g({...p,task_mode:M}),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Wo,{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(Wo,{value:"replace",id:"mode_replace"}),e.jsx(T,{htmlFor:"mode_replace",className:"font-normal",children:"替换模式 - 用模板配置完全替换现有配置"})]})]})]})]}),c===2&&m&&e.jsxs("div",{className:"space-y-4",children:[p.apply_providers&&m.existing_providers.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs(ht,{children:[e.jsx(Yt,{className:"h-4 w-4"}),e.jsx(Jn,{children:"发现已有的提供商"}),e.jsx(ft,{children:"以下提供商的 URL 与您本地配置中的提供商匹配,将自动使用本地提供商:"})]}),e.jsx("div",{className:"space-y-2",children:m.existing_providers.map(({pack_provider:M,local_providers:S})=>e.jsxs("div",{className:"flex items-center gap-2 p-3 bg-muted rounded-lg",children:[e.jsx(Ot,{className:"w-4 h-4 text-green-500 flex-shrink-0"}),e.jsx("span",{className:"font-medium flex-shrink-0",children:M.name}),e.jsx(ra,{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(Ce,{variant:"outline",className:"ml-auto",children:"URL 匹配"})]}):e.jsxs(e.Fragment,{children:[e.jsxs(Pe,{value:N[M.name]||S[0].name,onValueChange:F=>j({...N,[M.name]:F}),children:[e.jsx(Be,{className:"w-[200px]",children:e.jsx(Fe,{})}),e.jsx(Ie,{children:S.map(F=>e.jsx(W,{value:F.name,children:F.name},F.name))})]}),e.jsxs(Ce,{variant:"outline",className:"ml-auto",children:[S.length," 个匹配"]})]})]},M.name))})]}),p.apply_providers&&m.new_providers.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs(ht,{variant:"destructive",children:[e.jsx(Lt,{className:"h-4 w-4"}),e.jsx(Jn,{children:"需要配置 API Key"}),e.jsx(ft,{children:"以下提供商在您的本地配置中不存在,需要填写 API Key:"})]}),e.jsx("div",{className:"space-y-4",children:m.new_providers.map(M=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(cx,{className:"w-4 h-4 text-amber-500"}),e.jsx("span",{className:"font-medium",children:M.name}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",M.base_url,")"]})]}),e.jsx(ne,{type:"password",placeholder:`输入 ${M.name} 的 API Key`,value:b[M.name]||"",onChange:S=>y({...b,[M.name]:S.target.value})})]},M.name))})]}),(!p.apply_providers||m.existing_providers.length===0&&m.new_providers.length===0)&&e.jsxs(ht,{children:[e.jsx(Ot,{className:"h-4 w-4"}),e.jsx(Jn,{children:"无需配置"}),e.jsx(ft,{children:"模板中没有提供商配置,或您选择不应用提供商。"})]})]}),c===3&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(ht,{children:[e.jsx(Yt,{className:"h-4 w-4"}),e.jsx(Jn,{children:"确认应用"}),e.jsx(ft,{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(Ot,{className:"w-4 h-4 text-green-500"}),e.jsx(Hl,{className:"w-4 h-4"}),e.jsxs("span",{children:["应用 ",r.providers.length," 个提供商配置"]})]}),p.apply_models&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Ot,{className:"w-4 h-4 text-green-500"}),e.jsx(Wn,{className:"w-4 h-4"}),e.jsxs("span",{children:["应用 ",r.models.length," 个模型配置"]})]}),p.apply_task_config&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Ot,{className:"w-4 h-4 text-green-500"}),e.jsx(er,{className:"w-4 h-4"}),e.jsxs("span",{children:[p.task_mode==="append"?"追加":"替换"," ",Object.keys(r.task_config).length," 个任务配置"]})]})]}),m&&m.new_providers.length>0&&e.jsxs(ht,{variant:"destructive",children:[e.jsx(Lt,{className:"h-4 w-4"}),e.jsxs(ft,{children:["将添加 ",m.new_providers.length," 个新提供商,请确保已填写正确的 API Key。"]})]})]})]}),e.jsxs(gt,{className:"flex justify-between",children:[e.jsx("div",{children:c>1&&!h&&e.jsx(_,{variant:"outline",onClick:()=>d(c-1),disabled:f,children:"上一步"})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(_,{variant:"outline",onClick:()=>l(!1),disabled:f,children:"取消"}),c<3?e.jsx(_,{onClick:()=>d(c+1),disabled:h,children:"下一步"}):e.jsxs(_,{onClick:w,disabled:f,children:[f&&e.jsx(Fs,{className:"w-4 h-4 mr-2 animate-spin"}),"应用模板"]})]})]})]})})}function tT(){return e.jsx("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:e.jsx(ts,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsx(ks,{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(ks,{className:"w-10 h-10"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(ks,{className:"h-8 w-2/3"}),e.jsx(ks,{className:"h-4 w-full"})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-4",children:[e.jsx(ks,{className:"h-4 w-24"}),e.jsx(ks,{className:"h-4 w-32"}),e.jsx(ks,{className:"h-4 w-28"}),e.jsx(ks,{className:"h-4 w-20"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(ks,{className:"h-6 w-20"}),e.jsx(ks,{className:"h-6 w-24"}),e.jsx(ks,{className:"h-6 w-16"})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 min-w-[160px]",children:[e.jsx(ks,{className:"h-10 w-full"}),e.jsx(ks,{className:"h-10 w-full"})]})]}),e.jsx(ks,{className:"h-px w-full"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsx(ks,{className:"h-24"}),e.jsx(ks,{className:"h-24"}),e.jsx(ks,{className:"h-24"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ks,{className:"h-10 w-32"}),e.jsx(ks,{className:"h-10 w-32"}),e.jsx(ks,{className:"h-10 w-32"})]}),e.jsx(ks,{className:"h-96 w-full"})]})]})})})}function aT(){const a=ha(),[l,r]=u.useState(!0);return u.useEffect(()=>{let c=!1;return(async()=>{try{const m=await dc();!c&&!m&&a({to:"/auth"})}catch{c||a({to:"/auth"})}finally{c||r(!1)}})(),()=>{c=!0}},[a]),{checking:l}}async function lT(){return await dc()}const nT=ti("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"}}),$b=u.forwardRef(({className:a,size:l,abbrTitle:r,children:c,...d},m)=>e.jsx("kbd",{className:P(nT({size:l,className:a})),ref:m,...d,children:r?e.jsx("abbr",{title:r,children:c}):c}));$b.displayName="Kbd";const rT=[{icon:id,title:"首页",description:"查看仪表板概览",path:"/",category:"概览"},{icon:Ua,title:"麦麦主程序配置",description:"配置麦麦的核心设置",path:"/config/bot",category:"配置"},{icon:Hl,title:"麦麦模型提供商配置",description:"配置模型提供商",path:"/config/modelProvider",category:"配置"},{icon:gv,title:"麦麦模型配置",description:"配置模型参数",path:"/config/model",category:"配置"},{icon:rd,title:"表情包管理",description:"管理麦麦的表情包",path:"/resource/emoji",category:"资源"},{icon:Ia,title:"表达方式管理",description:"管理麦麦的表达方式",path:"/resource/expression",category:"资源"},{icon:jv,title:"人物信息管理",description:"管理人物信息",path:"/resource/person",category:"资源"},{icon:Wr,title:"黑话管理",description:"管理麦麦学习到的黑话和俚语",path:"/resource/jargon",category:"资源"},{icon:t_,title:"统计信息",description:"查看使用统计",path:"/statistics",category:"监控"},{icon:xa,title:"插件市场",description:"浏览和安装插件",path:"/plugins",category:"扩展"},{icon:ux,title:"日志查看器",description:"查看系统日志",path:"/logs",category:"监控"},{icon:Sn,title:"系统设置",description:"配置系统参数",path:"/settings",category:"系统"}];function iT({open:a,onOpenChange:l}){const[r,c]=u.useState(""),[d,m]=u.useState(0),h=ha(),f=rT.filter(N=>N.title.toLowerCase().includes(r.toLowerCase())||N.description.toLowerCase().includes(r.toLowerCase())||N.category.toLowerCase().includes(r.toLowerCase())),p=u.useCallback(N=>{h({to:N}),l(!1),c(""),m(0)},[h,l]),g=u.useCallback(N=>{N.key==="ArrowDown"?(N.preventDefault(),m(j=>(j+1)%f.length)):N.key==="ArrowUp"?(N.preventDefault(),m(j=>(j-1+f.length)%f.length)):N.key==="Enter"&&f[d]&&(N.preventDefault(),p(f[d].path))},[f,d,p]);return e.jsx(Qs,{open:a,onOpenChange:l,children:e.jsxs(Hs,{className:"max-w-2xl p-0 gap-0",children:[e.jsxs(qs,{className:"px-4 pt-4 pb-0",children:[e.jsx(Vs,{className:"sr-only",children:"搜索"}),e.jsxs("div",{className:"relative",children:[e.jsx($t,{className:"absolute left-3 top-1/2 h-5 w-5 -translate-y-1/2 text-muted-foreground"}),e.jsx(ne,{value:r,onChange:N=>{c(N.target.value),m(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(ts,{className:"h-[400px]",children:f.length>0?e.jsx("div",{className:"p-2",children:f.map((N,j)=>{const b=N.icon;return e.jsxs("button",{onClick:()=>p(N.path),onMouseEnter:()=>m(j),className:P("w-full flex items-center gap-3 px-3 py-2.5 rounded-md text-left transition-colors",j===d?"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($t,{className:"h-12 w-12 text-muted-foreground/50 mb-4"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:r?"未找到匹配的页面":"输入关键词开始搜索"})]})})}),e.jsx("div",{className:"border-t px-4 py-3 flex items-center justify-between text-xs text-muted-foreground",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"↑"}),e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"↓"}),"导航"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"Enter"}),"选择"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"Esc"}),"关闭"]})]})})]})})}function cT(){const a=window.location.protocol==="http:",l=window.location.hostname.toLowerCase(),r=l==="localhost"||l==="127.0.0.1"||l==="::1",c=sessionStorage.getItem("http-warning-dismissed")==="true",[d,m]=u.useState(a&&!r&&!c),[h,f]=u.useState(!1),p=()=>{f(!0),m(!1),sessionStorage.setItem("http-warning-dismissed","true")};return!d||h?null:e.jsx("div",{className:"relative bg-amber-500/10 border-b border-amber-500/20 backdrop-blur-sm",children:e.jsx("div",{className:"container mx-auto px-4 py-3",children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1",children:[e.jsx(Lt,{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(Sa,{className:"h-4 w-4"})})]})})})}function oT(){const[a,l]=u.useState(0),[r,c]=u.useState(!1),d=u.useRef(null);u.useEffect(()=>{const g=N=>{const j=N.target;if(j.scrollHeight>j.clientHeight+100){d.current=j;const b=j.scrollTop,y=j.scrollHeight-j.clientHeight,w=y>0?b/y*100:0;l(w),c(b>300)}};return window.addEventListener("scroll",g,{capture:!0,passive:!0}),()=>window.removeEventListener("scroll",g,{capture:!0})},[]);const m=()=>{d.current?.scrollTo({top:0,behavior:"smooth"})},h=18,f=2*Math.PI*h,p=f-a/100*f;return e.jsx("div",{className:P("fixed bottom-24 right-8 z-50 transition-all duration-500 ease-in-out transform",r?"translate-x-0 opacity-100":"translate-x-32 opacity-0 pointer-events-none"),children:e.jsxs(_,{variant:"outline",size:"icon",className: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:m,"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(a_,{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"})]})})}function dT({children:a}){const{checking:l}=aT(),[r,c]=u.useState(!0),[d,m]=u.useState(!1),[h,f]=u.useState(!1),[p,g]=u.useState(!1),{theme:N,setTheme:j}=vx(),b=nw();if(u.useEffect(()=>{if(r)g(!1);else{const S=setTimeout(()=>{g(!0)},350);return()=>clearTimeout(S)}},[r]),u.useEffect(()=>{const S=F=>{(F.metaKey||F.ctrlKey)&&F.key==="k"&&(F.preventDefault(),f(!0))};return window.addEventListener("keydown",S),()=>window.removeEventListener("keydown",S)},[]),l)return e.jsx("div",{className:"flex h-screen items-center justify-center bg-background",children:e.jsx("div",{className:"text-muted-foreground",children:"正在验证登录状态..."})});const y=[{title:"概览",items:[{icon:id,label:"首页",path:"/"}]},{title:"麦麦配置编辑",items:[{icon:Ua,label:"麦麦主程序配置",path:"/config/bot"},{icon:Hl,label:"AI模型厂商配置",path:"/config/modelProvider",tourId:"sidebar-model-provider"},{icon:gv,label:"模型管理与分配",path:"/config/model",tourId:"sidebar-model-management"},{icon:zg,label:"麦麦适配器配置",path:"/config/adapter"}]},{title:"麦麦资源管理",items:[{icon:rd,label:"表情包管理",path:"/resource/emoji"},{icon:Ia,label:"表达方式管理",path:"/resource/expression"},{icon:Wr,label:"黑话管理",path:"/resource/jargon"},{icon:jv,label:"人物信息管理",path:"/resource/person"},{icon:xv,label:"知识库图谱可视化",path:"/resource/knowledge-graph"},{icon:Zr,label:"麦麦知识库管理",path:"/resource/knowledge-base"}]},{title:"扩展与监控",items:[{icon:xa,label:"插件市场",path:"/plugins"},{icon:fv,label:"配置模板市场",path:"/config/pack-market"},{icon:zg,label:"插件配置",path:"/plugin-config"},{icon:ux,label:"日志查看器",path:"/logs"},{icon:nx,label:"计划器&回复器监控",path:"/planner-monitor"},{icon:Ia,label:"本地聊天室",path:"/chat"}]},{title:"系统",items:[{icon:Sn,label:"系统设置",path:"/settings"}]}],z=N==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":N,M=async()=>{await B_()};return e.jsx(Zv,{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",r?"lg:w-64":"lg:w-16",d?"translate-x-0":"-translate-x-full lg:translate-x-0"),children:[e.jsx("div",{className:"flex h-16 items-center border-b px-4",children:e.jsxs("div",{className:P("relative flex items-center justify-center flex-1 transition-all overflow-hidden","lg:flex-1",!r&&"lg:flex-none lg:w-8"),children:[e.jsxs("div",{className:P("flex items-baseline gap-2",!r&&"lg:hidden"),children:[e.jsx("span",{className:"font-bold text-xl text-primary-gradient whitespace-nowrap",children:"MaiBot WebUI"}),e.jsx("span",{className:"text-xs text-primary/60 whitespace-nowrap",children:v2()})]}),!r&&e.jsx("span",{className:"hidden lg:block font-bold text-primary-gradient text-2xl",children:"M"})]})}),e.jsx(ts,{className:P("flex-1 overflow-x-hidden",!r&&"lg:w-16"),children:e.jsx("nav",{className:P("p-4",!r&&"lg:p-2 lg:w-16"),children:e.jsx("ul",{className:P("space-y-6",!r&&"lg:space-y-3 lg:w-full"),children:y.map((S,F)=>e.jsxs("li",{children:[e.jsx("div",{className:P("px-3 h-[1.25rem]","mb-2",!r&&"lg:mb-1 lg:invisible"),children:e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground/60 whitespace-nowrap",children:S.title})}),!r&&F>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}),R=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",r?"gap-3":"gap-3 lg:gap-0"),children:[e.jsx(R,{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",r?"opacity-100 max-w-[200px]":"opacity-100 max-w-[200px] lg:opacity-0 lg:max-w-0 lg:overflow-hidden"),children:E.label})]})]});return e.jsx("li",{className:"relative",children:e.jsxs(Wv,{children:[e.jsx(eN,{asChild:!0,children:e.jsx(Kn,{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",r?"px-3":"px-3 lg:px-0 lg:justify-center lg:w-12 lg:mx-auto"),onClick:()=>m(!1),children:H})}),p&&e.jsx(Tx,{side:"right",className:"hidden lg:block",children:e.jsx("p",{children:E.label})})]})},E.path)})})]},S.title))})})})]}),d&&e.jsx("div",{className:"fixed inset-0 z-40 bg-black/50 lg:hidden",onClick:()=>m(!1)}),e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsx(cT,{}),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:()=>m(!d),className:"rounded-lg p-2 hover:bg-accent lg:hidden",children:e.jsx(l_,{className:"h-5 w-5"})}),e.jsx("button",{onClick:()=>c(!r),className:"hidden rounded-lg p-2 hover:bg-accent lg:block",title:r?"收起侧边栏":"展开侧边栏",children:e.jsx(Pa,{className:P("h-5 w-5 transition-transform",!r&&"rotate-180")})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Kn,{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(n_,{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($t,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"搜索..."}),e.jsxs($b,{size:"sm",className:"absolute right-2 top-1/2 -translate-y-1/2",children:[e.jsx("span",{className:"text-xs",children:"⌘"}),"K"]})]}),e.jsx(iT,{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(r_,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"麦麦文档"})]}),e.jsx("button",{onClick:S=>{h2(z==="dark"?"light":"dark",j,S)},className:"rounded-lg p-2 hover:bg-accent",title:z==="dark"?"切换到浅色模式":"切换到深色模式",children:z==="dark"?e.jsx(ix,{className:"h-5 w-5"}):e.jsx(tc,{className:"h-5 w-5"})}),e.jsx("div",{className:"h-6 w-px bg-border"}),e.jsxs(_,{variant:"ghost",size:"sm",onClick:M,className:"gap-2",title:"登出系统",children:[e.jsx(i_,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"登出"})]})]})]}),e.jsx("main",{className:"flex-1 overflow-hidden bg-background",children:a}),e.jsx(oT,{})]})]})})}function uT(a){const l=a.split(` +`)}async function K3(a,l){const r=l.fontEmbedCSS!=null?l.fontEmbedCSS:l.skipFonts?null:await G3(a,l);if(r){const c=document.createElement("style"),d=document.createTextNode(r);c.appendChild(d),a.firstChild?a.insertBefore(c,a.firstChild):a.appendChild(c)}}async function Q3(a,l={}){const{width:r,height:c}=FN(a,l),d=await jd(a,l,!0);return await K3(d,l),await QN(d,l),P3(d,l),await u3(d,r,c)}async function Y3(a,l={}){const{width:r,height:c}=FN(a,l),d=await Q3(a,l),m=await sd(d),h=document.createElement("canvas"),f=h.getContext("2d"),p=l.pixelRatio||c3(),g=l.canvasWidth||r,N=l.canvasHeight||c;return h.width=g*p,h.height=N*p,l.skipAutoScale||o3(h),h.style.width=`${g}`,h.style.height=`${N}`,l.backgroundColor&&(f.fillStyle=l.backgroundColor,f.fillRect(0,0,h.width,h.height)),f.drawImage(m,0,0,h.width,h.height),h}async function J3(a,l={}){return(await Y3(a,l)).toDataURL()}const $o=["#0088FE","#00C49F","#FFBB28","#FF8042","#8884d8","#82ca9d"];function X3(a){return a>=8760?"相当于全年无休,7x24小时在线!":a>=5e3?"相当于一位全职员工的年工作时长":a>=2e3?"相当于看完了 1000 部电影":a>=1e3?"相当于环球飞行 80 次":a>=500?"相当于读完了 100 本书":a>=100?"相当于马拉松跑了 25 次":"虽然不多,但每一刻都很珍贵"}function Z3(a){return a>=1e3?"夜深人静时的知心好友":a>=500?"午夜场的常客":a>=100?"偶尔熬夜的小伙伴":a>=50?"深夜有时也会陪你聊聊":"早睡早起,健康作息"}function W3(a){const l=a/1e6;return l>=100?"思考量堪比一座图书馆":l>=50?"相当于写了一部百科全书":l>=10?"脑细胞估计消耗了不少":l>=1?"也算是费了一番脑筋":"轻轻松松,游刃有余"}function e5(a){return a>=1e3?"这钱够吃一年的泡面了":a>=500?"相当于买了一台游戏机":a>=100?"够请大家喝几杯奶茶":a>=50?"一顿火锅的钱":a>=10?"几杯咖啡的价格":"省钱小能手"}function s5(a){return a>=80?"沉默是金,惜字如金":a>=60?"话不多但句句到位":a>=40?"该说的时候才开口":a>=20?"能聊的都聊了":"话痨本痨,有问必答"}function t5(a){return a>=1e4?"眼睛都快看花了":a>=5e3?"堪比专业摄影师的阅片量":a>=1e3?"看图小达人":a>=500?"图片鉴赏家":a>=100?"偶尔欣赏一下美图":"图片?有空再看"}function a5(a){return a>=500?"在不断的纠正中成长":a>=200?"学习永无止境":a>=100?"虚心接受,积极改正":a>=50?"偶尔也会犯错":a>=10?"表现还算不错":"完美表达,无需纠正"}function l5(a){return a>=1?"这次思考的价值堪比一顿大餐!":a>=.5?"为了这个问题,我可是认真思考了!":a>=.1?"下了点功夫,值得的!":a>=.01?"花了点小钱,但很值得":"小小思考,不足挂齿"}function n5(a,l){return a>=100?"这句话简直是万能钥匙!":a>=50?"百试不爽的经典回复":a>=20?`${l}的口头禅`:a>=10?"常用语录之一":"偶尔用用的小确幸"}function r5(a,l){return a?l>=1e3?"深夜的守护者,黑暗中的光芒":l>=500?"月亮是我的好朋友":l>=100?"越夜越精神,夜晚才是主场":"偶尔熬夜,享受宁静时光":l<=10?"作息规律,健康生活的典范":l<=50?"早睡早起,偶尔也会熬个夜":"虽然是早起鸟,但也会守候深夜"}function i5(a){return a>=1e3?"忙到飞起,键盘都要冒烟了":a>=500?"这天简直是话痨附体":a>=200?"社交达人上线":a>=100?"比平时活跃不少":a>=50?"小忙一下":"还算轻松的一天"}function c5(){const[a]=u.useState(2025),[l,r]=u.useState(null),[c,d]=u.useState(!0),[m,h]=u.useState(!1),[f,p]=u.useState(null),g=u.useRef(null),{toast:N}=nt(),j=u.useCallback(async()=>{try{d(!0),p(null);const y=await a3(a);r(y)}catch(y){p(y instanceof Error?y:new Error("获取年度报告失败"))}finally{d(!1)}},[a]),b=u.useCallback(async()=>{if(!(!g.current||!l)){h(!0),N({title:"正在生成图片",description:"请稍候..."});try{const y=g.current,w=getComputedStyle(document.documentElement),z=w.getPropertyValue("--background").trim()?`hsl(${w.getPropertyValue("--background").trim()})`:document.documentElement.classList.contains("dark")?"#0a0a0a":"#ffffff",M=y.style.width,S=y.style.maxWidth;y.style.width="1024px",y.style.maxWidth="1024px";const F=await J3(y,{quality:1,pixelRatio:2,backgroundColor:z,cacheBust:!0,filter:C=>!(C instanceof HTMLElement&&C.hasAttribute("data-export-btn"))});y.style.width=M,y.style.maxWidth=S;const E=document.createElement("a");E.download=`${l.bot_name}_${l.year}_年度总结.png`,E.href=F,E.click(),N({title:"导出成功",description:"年度报告已保存为图片"})}catch(y){console.error("导出图片失败:",y),N({title:"导出失败",description:"请重试",variant:"destructive"})}finally{h(!1)}}},[l,N]);return u.useEffect(()=>{j()},[j]),c?e.jsx(o5,{}):f?e.jsxs("div",{className:"flex h-screen items-center justify-center text-red-500",children:["获取年度报告失败: ",f.message]}):l?e.jsx(ts,{className:"h-[calc(100vh-4rem)]",children:e.jsx("div",{className:"min-h-screen bg-gradient-to-b from-background to-muted/50 p-4 md:p-8 print:p-0",ref:g,children:e.jsxs("div",{className:"mx-auto max-w-5xl space-y-8 print:space-y-4",children:[e.jsxs("header",{className:"relative overflow-hidden rounded-3xl bg-primary p-8 text-primary-foreground shadow-2xl print:rounded-none print:shadow-none",children:[e.jsx("div",{className:"absolute right-4 top-4 z-20 print:hidden","data-export-btn":!0,children:e.jsx(_,{variant:"secondary",size:"sm",onClick:b,disabled:m,className:"gap-2 bg-white/20 hover:bg-white/30 text-white border-white/30",children:m?e.jsxs(e.Fragment,{children:[e.jsx(Fs,{className:"h-4 w-4 animate-spin"}),"导出中..."]}):e.jsxs(e.Fragment,{children:[e.jsx(na,{className:"h-4 w-4"}),"保存图片"]})})}),e.jsxs("div",{className:"relative z-10 flex flex-col items-center text-center",children:[e.jsx(Yn,{className:"mb-4 h-16 w-16 animate-bounce"}),e.jsxs("h1",{className:"text-4xl font-bold tracking-tighter sm:text-6xl",children:[l.bot_name," ",l.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(Ko,{className:"h-4 w-4"}),e.jsxs("span",{children:["生成时间: ",l.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(da,{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(La,{title:"年度在线时长",value:`${l.time_footprint.total_online_hours} 小时`,description:X3(l.time_footprint.total_online_hours),icon:e.jsx(da,{className:"h-4 w-4"})}),e.jsx(La,{title:"最忙碌的一天",value:l.time_footprint.busiest_day||"N/A",description:i5(l.time_footprint.busiest_day_count),icon:e.jsx(Ko,{className:"h-4 w-4"})}),e.jsx(La,{title:"深夜互动 (0-4点)",value:`${l.time_footprint.midnight_chat_count} 次`,description:Z3(l.time_footprint.midnight_chat_count),icon:e.jsx(tc,{className:"h-4 w-4"})}),e.jsx(La,{title:"作息属性",value:l.time_footprint.is_night_owl?"夜猫子":"早起鸟",description:r5(l.time_footprint.is_night_owl,l.time_footprint.midnight_chat_count),icon:l.time_footprint.is_night_owl?e.jsx(tc,{className:"h-4 w-4"}):e.jsx(ix,{className:"h-4 w-4"})})]}),e.jsxs(Te,{className:"overflow-hidden",children:[e.jsxs(Oe,{children:[e.jsx(Ue,{children:"24小时活跃时钟"}),e.jsxs(Ns,{children:[l.bot_name,"在一天中各个时段的活跃程度"]})]}),e.jsx(ze,{className:"h-[300px]",children:e.jsx(Uj,{width:"100%",height:"100%",children:e.jsxs(Bo,{data:l.time_footprint.hourly_distribution.map((y,w)=>({hour:`${w}点`,count:y})),children:[e.jsx(Ji,{strokeDasharray:"3 3",vertical:!1}),e.jsx(Xi,{dataKey:"hour"}),e.jsx(Gr,{}),e.jsx($j,{contentStyle:{borderRadius:"8px",border:"none",boxShadow:"0 4px 12px rgba(0,0,0,0.1)"},cursor:{fill:"transparent"}}),e.jsx(Zi,{dataKey:"count",fill:"hsl(var(--primary))",radius:[4,4,0,0]})]})})})]}),l.time_footprint.first_message_time&&e.jsx(Te,{className:"bg-muted/30 border-dashed",children:e.jsxs(ze,{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:l.time_footprint.first_message_time}),e.jsxs("p",{className:"text-lg",children:[e.jsx("span",{className:"font-semibold text-foreground",children:l.time_footprint.first_message_user})," 说:",e.jsxs("span",{className:"italic text-muted-foreground",children:['"',l.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(oc,{className:"h-8 w-8"}),e.jsx("h2",{children:"社交网络"})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsx(La,{title:"社交圈子",value:`${l.social_network.total_groups} 个群组`,description:`${l.bot_name}加入的群组总数`,icon:e.jsx(oc,{className:"h-4 w-4"})}),e.jsx(La,{title:"被呼叫次数",value:`${l.social_network.at_count+l.social_network.mentioned_count} 次`,description:"我的名字被大家频繁提起",icon:e.jsx(W1,{className:"h-4 w-4"})}),e.jsx(La,{title:"最长情陪伴",value:l.social_network.longest_companion_user||"N/A",description:`始终都在,已陪伴 ${l.social_network.longest_companion_days} 天`,icon:e.jsx(ei,{className:"h-4 w-4 text-red-500"})})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(Te,{children:[e.jsx(Oe,{children:e.jsx(Ue,{children:"话痨群组 TOP5"})}),e.jsx(ze,{children:e.jsx("div",{className:"space-y-3",children:l.social_network.top_groups.length>0?l.social_network.top_groups.map((y,w)=>e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ce,{variant:w===0?"default":"secondary",className:"h-6 w-6 rounded-full p-0 flex items-center justify-center shrink-0",children:w+1}),e.jsx("span",{className:"font-medium truncate max-w-[120px]",children:y.group_name}),y.is_webui&&e.jsx(Ce,{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:[y.message_count," 条消息"]})]},y.group_id)):e.jsx("div",{className:"text-center text-muted-foreground py-4",children:"暂无数据"})})})]}),e.jsxs(Te,{children:[e.jsx(Oe,{children:e.jsx(Ue,{children:"年度最佳损友 TOP5"})}),e.jsx(ze,{children:e.jsx("div",{className:"space-y-3",children:l.social_network.top_users.length>0?l.social_network.top_users.map((y,w)=>e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ce,{variant:w===0?"default":"secondary",className:"h-6 w-6 rounded-full p-0 flex items-center justify-center shrink-0",children:w+1}),e.jsx("span",{className:"font-medium truncate max-w-[120px]",children:y.user_nickname}),y.is_webui&&e.jsx(Ce,{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:[y.message_count," 次互动"]})]},y.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(hx,{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(La,{title:"年度 Token 消耗",value:(l.brain_power.total_tokens/1e6).toFixed(2)+" M",description:W3(l.brain_power.total_tokens),icon:e.jsx(sl,{className:"h-4 w-4"})}),e.jsx(La,{title:"年度总花费",value:`$${l.brain_power.total_cost.toFixed(2)}`,description:e5(l.brain_power.total_cost),icon:e.jsx("span",{className:"font-bold",children:"$"})}),e.jsx(La,{title:"高冷指数",value:`${l.brain_power.silence_rate}%`,description:s5(l.brain_power.silence_rate),icon:e.jsx(tc,{className:"h-4 w-4"})}),e.jsx(La,{title:"最高兴趣值",value:l.brain_power.max_interest_value??"N/A",description:l.brain_power.max_interest_time?`出现在 ${l.brain_power.max_interest_time}`:"暂无数据",icon:e.jsx(ei,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(Te,{children:[e.jsx(Oe,{children:e.jsx(Ue,{children:"模型偏好分布"})}),e.jsx(ze,{children:e.jsx("div",{className:"space-y-3",children:l.brain_power.model_distribution.slice(0,5).map((y,w)=>{const z=l.brain_power.model_distribution[0]?.count||1,M=Math.round(y.count/z*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:y.model}),e.jsxs("span",{className:"text-muted-foreground",children:[y.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:`${M}%`,backgroundColor:$o[w%$o.length]}})})]},y.model)})})})]}),l.brain_power.top_reply_models&&l.brain_power.top_reply_models.length>0&&e.jsxs(Te,{children:[e.jsxs(Oe,{children:[e.jsx(Ue,{children:"最喜欢的回复模型 TOP5"}),e.jsxs(Ns,{children:[l.bot_name,"用来回复消息的模型偏好"]})]}),e.jsx(ze,{children:e.jsx("div",{className:"space-y-3",children:l.brain_power.top_reply_models.map((y,w)=>{const z=l.brain_power.top_reply_models[0]?.count||1,M=Math.round(y.count/z*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:y.model}),e.jsxs("span",{className:"text-muted-foreground",children:[y.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:`${M}%`,backgroundColor:$o[w%$o.length]}})})]},y.model)})})})]}),l.brain_power.top_token_consumers&&l.brain_power.top_token_consumers.length>0&&e.jsxs(Te,{children:[e.jsxs(Oe,{children:[e.jsx(Ue,{children:"烧钱大户 TOP3"}),e.jsx(Ns,{children:"谁消耗了最多的 API 额度"})]}),e.jsx(ze,{children:e.jsx("div",{className:"space-y-6",children:l.brain_power.top_token_consumers.map(y=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between text-sm font-medium",children:[e.jsxs("span",{children:["用户 ",y.user_id]}),e.jsxs("span",{children:["$",y.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:`${y.cost/(l.brain_power.top_token_consumers[0]?.cost||1)*100}%`}})})]},y.user_id))})})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(Te,{className:"bg-gradient-to-br from-amber-50 to-orange-50 dark:from-amber-950/20 dark:to-orange-950/20",children:[e.jsx(Oe,{children:e.jsxs(Ue,{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-2xl",children:"💰"}),"最昂贵的一次思考"]})}),e.jsxs(ze,{className:"text-center",children:[e.jsxs("div",{className:"text-4xl font-bold text-amber-600 dark:text-amber-400",children:["$",l.brain_power.most_expensive_cost.toFixed(4)]}),l.brain_power.most_expensive_time&&e.jsxs("p",{className:"mt-2 text-sm text-muted-foreground",children:["发生在 ",l.brain_power.most_expensive_time]}),e.jsx("p",{className:"mt-4 text-sm text-muted-foreground",children:l5(l.brain_power.most_expensive_cost)})]})]}),e.jsxs(Te,{className:"bg-gradient-to-br from-indigo-50 to-blue-50 dark:from-indigo-950/20 dark:to-blue-950/20",children:[e.jsx(Oe,{children:e.jsxs(Ue,{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-2xl",children:"🧠"}),"思考深度"]})}),e.jsxs(ze,{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:l.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:l.brain_power.max_reasoning_length?.toLocaleString()||0}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"最长思考字数"})]})]}),l.brain_power.max_reasoning_time&&e.jsxs("p",{className:"mt-4 text-center text-xs text-muted-foreground",children:["最深沉的思考发生在 ",l.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(rd,{className:"h-8 w-8"}),e.jsx("h2",{children:"个性与表达"})]}),(l.expression_vibe.late_night_reply||l.expression_vibe.favorite_reply)&&e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[l.expression_vibe.late_night_reply&&e.jsxs(Te,{className:"bg-gradient-to-br from-indigo-50 to-violet-50 dark:from-indigo-950/20 dark:to-violet-950/20",children:[e.jsxs(Oe,{children:[e.jsxs(Ue,{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-2xl",children:"🌙"}),"深夜还在回复"]}),e.jsxs(Ns,{children:["凌晨 ",l.expression_vibe.late_night_reply.time,",",l.bot_name,"还在回复..."]})]}),e.jsxs(ze,{className:"text-center",children:[e.jsxs("p",{className:"text-lg italic text-muted-foreground",children:['"',l.expression_vibe.late_night_reply.content,'"']}),e.jsx("p",{className:"mt-4 text-sm text-muted-foreground",children:"是有什么心事吗?"})]})]}),l.expression_vibe.favorite_reply&&e.jsxs(Te,{className:"bg-gradient-to-br from-rose-50 to-pink-50 dark:from-rose-950/20 dark:to-pink-950/20",children:[e.jsxs(Oe,{children:[e.jsxs(Ue,{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-2xl",children:"💬"}),"最喜欢的回复"]}),e.jsxs(Ns,{children:["使用了 ",l.expression_vibe.favorite_reply.count," 次"]})]}),e.jsxs(ze,{className:"text-center",children:[e.jsxs("p",{className:"text-lg font-medium text-primary",children:['"',l.expression_vibe.favorite_reply.content,'"']}),e.jsx("p",{className:"mt-4 text-sm text-muted-foreground",children:n5(l.expression_vibe.favorite_reply.count,l.bot_name)})]})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(Te,{className:"bg-gradient-to-br from-pink-50 to-purple-50 dark:from-pink-950/20 dark:to-purple-950/20",children:[e.jsxs(Oe,{children:[e.jsx(Ue,{children:"使用最多的表情包 TOP3"}),e.jsx(Ns,{children:"年度最爱的表情包们"})]}),e.jsx(ze,{children:l.expression_vibe.top_emojis&&l.expression_vibe.top_emojis.length>0?e.jsx("div",{className:"flex justify-center gap-4",children:l.expression_vibe.top_emojis.slice(0,3).map((y,w)=>e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:`/api/webui/emoji/${y.id}/thumbnail?original=true`,alt:`TOP ${w+1}`,className:"h-24 w-24 rounded-lg object-cover shadow-md transition-transform hover:scale-105"}),e.jsx(Ce,{className:P("absolute -top-2 -right-2",w===0?"bg-yellow-500":w===1?"bg-gray-400":"bg-amber-700"),children:w+1})]}),e.jsxs("p",{className:"mt-2 text-sm text-muted-foreground",children:[y.usage_count," 次"]})]},y.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(Te,{children:[e.jsxs(Oe,{children:[e.jsx(Ue,{children:"印象最深刻的表达风格"}),e.jsxs(Ns,{children:[l.bot_name,"最常使用的表达方式"]})]}),e.jsx(ze,{children:e.jsx("div",{className:"flex flex-wrap gap-2",children:l.expression_vibe.top_expressions.map((y,w)=>e.jsxs(Ce,{variant:"outline",className:P("px-3 py-1 text-sm",w===0&&"border-primary bg-primary/10 text-primary text-base px-4 py-2"),children:[y.style," (",y.count,")"]},y.style))})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(La,{title:"图片鉴赏",value:`${l.expression_vibe.image_processed_count} 张`,description:t5(l.expression_vibe.image_processed_count),icon:e.jsx(xx,{className:"h-4 w-4"})}),e.jsx(La,{title:"成长的足迹",value:`${l.expression_vibe.rejected_expression_count} 次`,description:a5(l.expression_vibe.rejected_expression_count),icon:e.jsx(sl,{className:"h-4 w-4"})})]})]})]}),l.expression_vibe.action_types.length>0&&e.jsxs(Te,{children:[e.jsxs(Oe,{children:[e.jsxs(Ue,{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-2xl",children:"⚡"}),"行动派"]}),e.jsx(Ns,{children:"除了聊天,我还帮大家做了这些事"})]}),e.jsx(ze,{children:e.jsx("div",{className:"flex flex-wrap gap-3",children:l.expression_vibe.action_types.map(y=>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:y.action}),e.jsxs(Ce,{variant:"secondary",children:[y.count," 次"]})]},y.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(e_,{className:"h-8 w-8"}),e.jsx("h2",{children:"趣味成就"})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsxs(Te,{className:"col-span-1 md:col-span-2",children:[e.jsxs(Oe,{children:[e.jsx(Ue,{children:'新学到的"黑话"'}),e.jsxs(Ns,{children:["今年我学会了 ",l.achievements.new_jargon_count," 个新词"]})]}),e.jsx(ze,{children:e.jsx("div",{className:"flex flex-wrap gap-3",children:l.achievements.sample_jargons.map(y=>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:y.content}),e.jsx("div",{className:"text-xs text-muted-foreground mt-1 line-clamp-2 max-w-[200px]",children:y.meaning||"暂无解释"})]},y.content))})})]}),e.jsx(Te,{className:"flex flex-col justify-center items-center bg-primary text-primary-foreground",children:e.jsxs(ze,{className:"flex flex-col items-center justify-center p-6 text-center",children:[e.jsx(Ia,{className:"h-12 w-12 mb-4 opacity-80"}),e.jsx("div",{className:"text-4xl font-bold mb-2",children:l.achievements.total_messages.toLocaleString()}),e.jsx("div",{className:"text-sm opacity-80",children:"年度总消息数"}),e.jsxs("div",{className:"mt-4 text-xs opacity-60",children:["其中回复了 ",l.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 La({title:a,value:l,description:r,icon:c}){return e.jsxs(Te,{children:[e.jsxs(Oe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Ue,{className:"text-sm font-medium",children:a}),e.jsx("div",{className:"text-muted-foreground",children:c})]}),e.jsxs(ze,{children:[e.jsx("div",{className:"text-2xl font-bold",children:l}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r})]})]})}function o5(){return e.jsxs("div",{className:"container mx-auto space-y-8 p-8",children:[e.jsx(ks,{className:"h-64 w-full rounded-3xl"}),e.jsx("div",{className:"grid gap-4 md:grid-cols-4",children:[...Array(4)].map((a,l)=>e.jsx(ks,{className:"h-32 w-full"},l))}),e.jsx(ks,{className:"h-96 w-full"})]})}var vd="DropdownMenu",[d5]=ld(vd,[Oj]),fa=Oj(),[u5,JN]=d5(vd),XN=a=>{const{__scopeDropdownMenu:l,children:r,dir:c,open:d,defaultOpen:m,onOpenChange:h,modal:f=!0}=a,p=fa(l),g=u.useRef(null),[N,j]=ad({prop:d,defaultProp:m??!1,onChange:h,caller:vd});return e.jsx(u5,{scope:l,triggerId:Ym(),triggerRef:g,contentId:Ym(),open:N,onOpenChange:j,onOpenToggle:u.useCallback(()=>j(b=>!b),[j]),modal:f,children:e.jsx(Vw,{...p,open:N,onOpenChange:j,dir:c,modal:f,children:r})})};XN.displayName=vd;var ZN="DropdownMenuTrigger",WN=u.forwardRef((a,l)=>{const{__scopeDropdownMenu:r,disabled:c=!1,...d}=a,m=JN(ZN,r),h=fa(r);return e.jsx(Gw,{asChild:!0,...h,children:e.jsx(ar.button,{type:"button",id:m.triggerId,"aria-haspopup":"menu","aria-expanded":m.open,"aria-controls":m.open?m.contentId:void 0,"data-state":m.open?"open":"closed","data-disabled":c?"":void 0,disabled:c,...d,ref:_1(l,m.triggerRef),onPointerDown:_n(a.onPointerDown,f=>{!c&&f.button===0&&f.ctrlKey===!1&&(m.onOpenToggle(),m.open||f.preventDefault())}),onKeyDown:_n(a.onKeyDown,f=>{c||(["Enter"," "].includes(f.key)&&m.onOpenToggle(),f.key==="ArrowDown"&&m.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(f.key)&&f.preventDefault())})})})});WN.displayName=ZN;var m5="DropdownMenuPortal",eb=a=>{const{__scopeDropdownMenu:l,...r}=a,c=fa(l);return e.jsx(Uw,{...c,...r})};eb.displayName=m5;var sb="DropdownMenuContent",tb=u.forwardRef((a,l)=>{const{__scopeDropdownMenu:r,...c}=a,d=JN(sb,r),m=fa(r),h=u.useRef(!1);return e.jsx($w,{id:d.contentId,"aria-labelledby":d.triggerId,...m,...c,ref:l,onCloseAutoFocus:_n(a.onCloseAutoFocus,f=>{h.current||d.triggerRef.current?.focus(),h.current=!1,f.preventDefault()}),onInteractOutside:_n(a.onInteractOutside,f=>{const p=f.detail.originalEvent,g=p.button===0&&p.ctrlKey===!0,N=p.button===2||g;(!d.modal||N)&&(h.current=!0)}),style:{...a.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});tb.displayName=sb;var x5="DropdownMenuGroup",h5=u.forwardRef((a,l)=>{const{__scopeDropdownMenu:r,...c}=a,d=fa(r);return e.jsx(Kw,{...d,...c,ref:l})});h5.displayName=x5;var f5="DropdownMenuLabel",ab=u.forwardRef((a,l)=>{const{__scopeDropdownMenu:r,...c}=a,d=fa(r);return e.jsx(Hw,{...d,...c,ref:l})});ab.displayName=f5;var p5="DropdownMenuItem",lb=u.forwardRef((a,l)=>{const{__scopeDropdownMenu:r,...c}=a,d=fa(r);return e.jsx(Bw,{...d,...c,ref:l})});lb.displayName=p5;var g5="DropdownMenuCheckboxItem",nb=u.forwardRef((a,l)=>{const{__scopeDropdownMenu:r,...c}=a,d=fa(r);return e.jsx(Iw,{...d,...c,ref:l})});nb.displayName=g5;var j5="DropdownMenuRadioGroup",v5=u.forwardRef((a,l)=>{const{__scopeDropdownMenu:r,...c}=a,d=fa(r);return e.jsx(Qw,{...d,...c,ref:l})});v5.displayName=j5;var N5="DropdownMenuRadioItem",rb=u.forwardRef((a,l)=>{const{__scopeDropdownMenu:r,...c}=a,d=fa(r);return e.jsx(Fw,{...d,...c,ref:l})});rb.displayName=N5;var b5="DropdownMenuItemIndicator",ib=u.forwardRef((a,l)=>{const{__scopeDropdownMenu:r,...c}=a,d=fa(r);return e.jsx(Pw,{...d,...c,ref:l})});ib.displayName=b5;var y5="DropdownMenuSeparator",cb=u.forwardRef((a,l)=>{const{__scopeDropdownMenu:r,...c}=a,d=fa(r);return e.jsx(qw,{...d,...c,ref:l})});cb.displayName=y5;var w5="DropdownMenuArrow",_5=u.forwardRef((a,l)=>{const{__scopeDropdownMenu:r,...c}=a,d=fa(r);return e.jsx(Yw,{...d,...c,ref:l})});_5.displayName=w5;var S5="DropdownMenuSubTrigger",ob=u.forwardRef((a,l)=>{const{__scopeDropdownMenu:r,...c}=a,d=fa(r);return e.jsx(Ow,{...d,...c,ref:l})});ob.displayName=S5;var k5="DropdownMenuSubContent",db=u.forwardRef((a,l)=>{const{__scopeDropdownMenu:r,...c}=a,d=fa(r);return e.jsx(Lw,{...d,...c,ref:l,style:{...a.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});db.displayName=k5;var C5=XN,T5=WN,E5=eb,ub=tb,mb=ab,xb=lb,hb=nb,fb=rb,pb=ib,gb=cb,jb=ob,vb=db;const M5=C5,A5=T5,z5=u.forwardRef(({className:a,inset:l,children:r,...c},d)=>e.jsxs(jb,{ref:d,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",l&&"pl-8",a),...c,children:[r,e.jsx(ra,{className:"ml-auto h-4 w-4"})]}));z5.displayName=jb.displayName;const R5=u.forwardRef(({className:a,...l},r)=>e.jsx(vb,{ref:r,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",a),...l}));R5.displayName=vb.displayName;const Nb=u.forwardRef(({className:a,sideOffset:l=4,...r},c)=>e.jsx(E5,{children:e.jsx(ub,{ref:c,sideOffset:l,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",a),...r})}));Nb.displayName=ub.displayName;const bb=u.forwardRef(({className:a,inset:l,...r},c)=>e.jsx(xb,{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",l&&"pl-8",a),...r}));bb.displayName=xb.displayName;const D5=u.forwardRef(({className:a,children:l,checked:r,...c},d)=>e.jsxs(hb,{ref:d,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",a),checked:r,...c,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(pb,{children:e.jsx(Ot,{className:"h-4 w-4"})})}),l]}));D5.displayName=hb.displayName;const O5=u.forwardRef(({className:a,children:l,...r},c)=>e.jsxs(fb,{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",a),...r,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(pb,{children:e.jsx(Vo,{className:"h-2 w-2 fill-current"})})}),l]}));O5.displayName=fb.displayName;const L5=u.forwardRef(({className:a,inset:l,...r},c)=>e.jsx(mb,{ref:c,className:P("px-2 py-1.5 text-sm font-semibold",l&&"pl-8",a),...r}));L5.displayName=mb.displayName;const U5=u.forwardRef(({className:a,...l},r)=>e.jsx(gb,{ref:r,className:P("-mx-1 my-1 h-px bg-muted",a),...l}));U5.displayName=gb.displayName;const Qm=[{value:"created_at",label:"最新发布",icon:da},{value:"downloads",label:"下载最多",icon:na},{value:"likes",label:"最受欢迎",icon:ei}];function $5(){const a=ha(),[l,r]=u.useState([]),[c,d]=u.useState(!0),[m,h]=u.useState(""),[f,p]=u.useState("downloads"),[g,N]=u.useState(1),[j,b]=u.useState(1),[y,w]=u.useState(0),[z,M]=u.useState(new Set),[S,F]=u.useState(new Set),E=cN(),C=u.useCallback(async()=>{d(!0);try{const L=await m4({status:"approved",page:g,page_size:12,search:m||void 0,sort_by:f,sort_order:"desc"});r(L.packs),b(L.total_pages),w(L.total);const me=new Set;for(const Ne of L.packs)await iN(Ne.id,E)&&me.add(Ne.id);M(me)}catch(L){console.error("加载 Pack 列表失败:",L),aa({title:"加载 Pack 列表失败",variant:"destructive"})}finally{d(!1)}},[g,m,f,E]);u.useEffect(()=>{C()},[C]);const R=L=>{L.preventDefault(),N(1),C()},H=async L=>{if(!S.has(L)){F(me=>new Set(me).add(L));try{const me=await rN(L,E);M(Ne=>{const je=new Set(Ne);return me.liked?je.add(L):je.delete(L),je}),r(Ne=>Ne.map(je=>je.id===L?{...je,likes:me.likes}:je))}catch(me){console.error("点赞失败:",me),aa({title:"点赞失败",variant:"destructive"})}finally{F(me=>{const Ne=new Set(me);return Ne.delete(L),Ne})}}},O=L=>{a({to:"/config/pack-market/$packId",params:{packId:L}})},X=Qm.find(L=>L.value===f)||Qm[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(xa,{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(ts,{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:R,className:"flex-1 min-w-[200px] max-w-md",children:e.jsxs("div",{className:"relative",children:[e.jsx($t,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(ne,{placeholder:"搜索模板名称、描述...",value:m,onChange:L=>h(L.target.value),className:"pl-10"})]})}),e.jsxs(M5,{children:[e.jsx(A5,{asChild:!0,children:e.jsxs(_,{variant:"outline",className:"min-w-[140px] gap-2",children:[e.jsx(s_,{className:"w-4 h-4"}),X.label,e.jsx(Ba,{className:"w-4 h-4 ml-auto"})]})}),e.jsx(Nb,{align:"end",children:Qm.map(L=>e.jsxs(bb,{onClick:()=>{p(L.value),N(1)},children:[e.jsx(L.icon,{className:"w-4 h-4 mr-2"}),L.label]},L.value))})]})]}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:["共找到 ",e.jsx("span",{className:"font-medium text-foreground",children:y})," 个模板"]}),c?e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:Array.from({length:6}).map((L,me)=>e.jsxs(Te,{children:[e.jsxs(Oe,{children:[e.jsx(ks,{className:"h-6 w-3/4"}),e.jsx(ks,{className:"h-4 w-full mt-2"})]}),e.jsx(ze,{children:e.jsx(ks,{className:"h-20 w-full"})}),e.jsx(od,{children:e.jsx(ks,{className:"h-9 w-full"})})]},me))}):l.length===0?e.jsx(Te,{className:"py-12",children:e.jsxs(ze,{className:"text-center text-muted-foreground",children:[e.jsx(xa,{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:l.map(L=>e.jsx(B5,{pack:L,liked:z.has(L.id),liking:S.has(L.id),onLike:()=>H(L.id),onView:()=>O(L.id)},L.id))}),j>1&&e.jsx(fx,{children:e.jsxs(px,{children:[e.jsx(Xn,{children:e.jsx($v,{onClick:()=>N(L=>Math.max(1,L-1)),className:g===1?"pointer-events-none opacity-50":"cursor-pointer"})}),Array.from({length:j},(L,me)=>me+1).filter(L=>L===1||L===j||Math.abs(L-g)<=1).map((L,me,Ne)=>{const je=me>0&&L-Ne[me-1]>1;return e.jsxs(Xn,{children:[je&&e.jsx("span",{className:"px-2",children:"..."}),e.jsx(jc,{onClick:()=>N(L),isActive:L===g,className:"cursor-pointer",children:L})]},L)}),e.jsx(Xn,{children:e.jsx(Bv,{onClick:()=>N(L=>Math.min(j,L+1)),className:g===j?"pointer-events-none opacity-50":"cursor-pointer"})})]})})]})})]})}function B5({pack:a,liked:l,liking:r,onLike:c,onView:d}){const m=h=>new Date(h).toLocaleDateString("zh-CN",{year:"numeric",month:"short",day:"numeric"});return e.jsxs(Te,{className:"flex flex-col hover:shadow-md transition-shadow",children:[e.jsxs(Oe,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsx(Ue,{className:"text-lg line-clamp-1",children:a.name}),e.jsxs(Ce,{variant:"secondary",className:"text-xs",children:["v",a.version]})]}),e.jsx(Ns,{className:"line-clamp-2 min-h-[40px]",children:a.description})]}),e.jsxs(ze,{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(Fl,{className:"w-3.5 h-3.5"}),a.author]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(da,{className:"w-3.5 h-3.5"}),m(a.created_at)]})]}),e.jsxs("div",{className:"flex gap-4 text-sm",children:[e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground",title:"提供商数量",children:[e.jsx(Hl,{className:"w-3.5 h-3.5"}),a.provider_count]}),e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground",title:"模型数量",children:[e.jsx(Wn,{className:"w-3.5 h-3.5"}),a.model_count]}),e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground",title:"任务配置数",children:[e.jsx(er,{className:"w-3.5 h-3.5"}),a.task_count]})]}),a.tags&&a.tags.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1",children:[a.tags.slice(0,3).map(h=>e.jsxs(Ce,{variant:"outline",className:"text-xs",children:[e.jsx(cd,{className:"w-2.5 h-2.5 mr-1"}),h]},h)),a.tags.length>3&&e.jsxs(Ce,{variant:"outline",className:"text-xs",children:["+",a.tags.length-3]})]})]}),e.jsx(od,{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(na,{className:"w-4 h-4"}),a.downloads]}),e.jsxs("button",{onClick:h=>{h.stopPropagation(),c()},disabled:r,className:`flex items-center gap-1 transition-colors ${l?"text-red-500":"hover:text-red-500"} ${r?"opacity-50":""}`,children:[e.jsx(ei,{className:`w-4 h-4 ${l?"fill-current":""}`}),a.likes]})]}),e.jsx(_,{size:"sm",onClick:d,children:"查看详情"})]})})]})}var ul="Accordion",I5=["Home","End","ArrowDown","ArrowUp","ArrowLeft","ArrowRight"],[Lx,P5,F5]=S1(ul),[Nd]=ld(ul,[F5,Lj]),Ux=Lj(),yb=Bs.forwardRef((a,l)=>{const{type:r,...c}=a,d=c,m=c;return e.jsx(Lx.Provider,{scope:a.__scopeAccordion,children:r==="multiple"?e.jsx(G5,{...m,ref:l}):e.jsx(V5,{...d,ref:l})})});yb.displayName=ul;var[wb,H5]=Nd(ul),[_b,q5]=Nd(ul,{collapsible:!1}),V5=Bs.forwardRef((a,l)=>{const{value:r,defaultValue:c,onValueChange:d=()=>{},collapsible:m=!1,...h}=a,[f,p]=ad({prop:r,defaultProp:c??"",onChange:d,caller:ul});return e.jsx(wb,{scope:a.__scopeAccordion,value:Bs.useMemo(()=>f?[f]:[],[f]),onItemOpen:p,onItemClose:Bs.useCallback(()=>m&&p(""),[m,p]),children:e.jsx(_b,{scope:a.__scopeAccordion,collapsible:m,children:e.jsx(Sb,{...h,ref:l})})})}),G5=Bs.forwardRef((a,l)=>{const{value:r,defaultValue:c,onValueChange:d=()=>{},...m}=a,[h,f]=ad({prop:r,defaultProp:c??[],onChange:d,caller:ul}),p=Bs.useCallback(N=>f((j=[])=>[...j,N]),[f]),g=Bs.useCallback(N=>f((j=[])=>j.filter(b=>b!==N)),[f]);return e.jsx(wb,{scope:a.__scopeAccordion,value:h,onItemOpen:p,onItemClose:g,children:e.jsx(_b,{scope:a.__scopeAccordion,collapsible:!0,children:e.jsx(Sb,{...m,ref:l})})})}),[K5,bd]=Nd(ul),Sb=Bs.forwardRef((a,l)=>{const{__scopeAccordion:r,disabled:c,dir:d,orientation:m="vertical",...h}=a,f=Bs.useRef(null),p=nd(f,l),g=P5(r),j=Wj(d)==="ltr",b=_n(a.onKeyDown,y=>{if(!I5.includes(y.key))return;const w=y.target,z=g().filter(X=>!X.ref.current?.disabled),M=z.findIndex(X=>X.ref.current===w),S=z.length;if(M===-1)return;y.preventDefault();let F=M;const E=0,C=S-1,R=()=>{F=M+1,F>C&&(F=E)},H=()=>{F=M-1,F{const{__scopeAccordion:r,value:c,...d}=a,m=bd(td,r),h=H5(td,r),f=Ux(r),p=Ym(),g=c&&h.value.includes(c)||!1,N=m.disabled||a.disabled;return e.jsx(Q5,{scope:r,open:g,disabled:N,triggerId:p,children:e.jsx(Mj,{"data-orientation":m.orientation,"data-state":zb(g),...f,...d,ref:l,disabled:N,open:g,onOpenChange:j=>{j?h.onItemOpen(c):h.onItemClose(c)}})})});kb.displayName=td;var Cb="AccordionHeader",Tb=Bs.forwardRef((a,l)=>{const{__scopeAccordion:r,...c}=a,d=bd(ul,r),m=$x(Cb,r);return e.jsx(ar.h3,{"data-orientation":d.orientation,"data-state":zb(m.open),"data-disabled":m.disabled?"":void 0,...c,ref:l})});Tb.displayName=Cb;var lx="AccordionTrigger",Eb=Bs.forwardRef((a,l)=>{const{__scopeAccordion:r,...c}=a,d=bd(ul,r),m=$x(lx,r),h=q5(lx,r),f=Ux(r);return e.jsx(Lx.ItemSlot,{scope:r,children:e.jsx(Jw,{"aria-disabled":m.open&&!h.collapsible||void 0,"data-orientation":d.orientation,id:m.triggerId,...f,...c,ref:l})})});Eb.displayName=lx;var Mb="AccordionContent",Ab=Bs.forwardRef((a,l)=>{const{__scopeAccordion:r,...c}=a,d=bd(ul,r),m=$x(Mb,r),h=Ux(r);return e.jsx(Xw,{role:"region","aria-labelledby":m.triggerId,"data-orientation":d.orientation,...h,...c,ref:l,style:{"--radix-accordion-content-height":"var(--radix-collapsible-content-height)","--radix-accordion-content-width":"var(--radix-collapsible-content-width)",...a.style}})});Ab.displayName=Mb;function zb(a){return a?"open":"closed"}var Y5=yb,J5=kb,X5=Tb,Rb=Eb,Db=Ab;const Z5=Y5,Ob=u.forwardRef(({className:a,...l},r)=>e.jsx(J5,{ref:r,className:P("border-b",a),...l}));Ob.displayName="AccordionItem";const Lb=u.forwardRef(({className:a,children:l,...r},c)=>e.jsx(X5,{className:"flex",children:e.jsxs(Rb,{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",a),...r,children:[l,e.jsx(Ba,{className:"h-4 w-4 shrink-0 transition-transform duration-200"})]})}));Lb.displayName=Rb.displayName;const Ub=u.forwardRef(({className:a,children:l,...r},c)=>e.jsx(Db,{ref:c,className:"overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down",...r,children:e.jsx("div",{className:P("pb-4 pt-0",a),children:l})}));Ub.displayName=Db.displayName;const W5={utils:"通用工具",utils_small:"轻量工具",tool_use:"工具调用",replyer:"回复生成",planner:"规划推理",vlm:"视觉模型",voice:"语音处理",embedding:"向量嵌入",lpmm_entity_extract:"实体提取",lpmm_rdf_build:"RDF构建",tts_instruct:"TTS指令",lpmm_qa:"问答模型"};function eT(){const{packId:a}=Pb.useParams(),l=ha(),[r,c]=u.useState(null),[d,m]=u.useState(!0),[h,f]=u.useState(!1),[p,g]=u.useState(!1),[N,j]=u.useState(!1),[b,y]=u.useState(1),[w,z]=u.useState(null),[M,S]=u.useState(!1),[F,E]=u.useState(!1),[C,R]=u.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,O]=u.useState({}),[X,L]=u.useState({}),me=cN(),Ne=u.useCallback(async()=>{if(a){m(!0);try{const D=await x4(a);c(D);const Q=await iN(a,me);f(Q)}catch(D){console.error("加载 Pack 失败:",D),aa({title:"加载模板失败",variant:"destructive"})}finally{m(!1)}}},[a,me]);u.useEffect(()=>{Ne()},[Ne]);const je=async()=>{if(!(!a||p)){g(!0);try{const D=await rN(a,me);f(D.liked),r&&c({...r,likes:D.likes})}catch(D){console.error("点赞失败:",D),aa({title:"点赞失败",variant:"destructive"})}finally{g(!1)}}},ce=async()=>{if(r){j(!0),y(1),S(!0);try{const D=await p4(r);z(D);const Q={};for(const ue of D.existing_providers)Q[ue.pack_provider.name]=ue.local_providers[0].name;O(Q);const B={};for(const ue of D.new_providers)B[ue.name]="";L(B)}catch(D){console.error("检测冲突失败:",D),aa({title:"检测配置冲突失败",variant:"destructive"}),j(!1)}finally{S(!1)}}},ge=async()=>{if(r){if(C.apply_providers&&w){for(const D of w.new_providers)if(!X[D.name]){aa({title:`请填写提供商 "${D.name}" 的 API Key`,variant:"destructive"});return}}E(!0);try{await g4(r,C,H,X),await f4(r.id,me),c({...r,downloads:r.downloads+1}),aa({title:"配置模板应用成功!"}),j(!1)}catch(D){console.error("应用 Pack 失败:",D),aa({title:D instanceof Error?D.message:"应用配置失败",variant:"destructive"})}finally{E(!1)}}},pe=D=>new Date(D).toLocaleDateString("zh-CN",{year:"numeric",month:"long",day:"numeric"});return d?e.jsx(tT,{}):r?e.jsx("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:e.jsx(ts,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsxs(_,{variant:"ghost",size:"sm",onClick:()=>l({to:"/config/pack-market"}),className:"gap-2",children:[e.jsx($a,{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(xa,{className:"w-10 h-10 text-primary mt-1"}),e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold flex items-center gap-2",children:[r.name,e.jsxs(Ce,{variant:"secondary",children:["v",r.version]})]}),e.jsx("p",{className:"text-muted-foreground mt-1",children:r.description})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-4 text-sm text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Fl,{className:"w-4 h-4"}),r.author]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(da,{className:"w-4 h-4"}),pe(r.created_at)]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(na,{className:"w-4 h-4"}),r.downloads," 次下载"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ei,{className:`w-4 h-4 ${h?"fill-red-500 text-red-500":""}`}),r.likes," 赞"]})]}),r.tags&&r.tags.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2",children:r.tags.map(D=>e.jsxs(Ce,{variant:"outline",children:[e.jsx(cd,{className:"w-3 h-3 mr-1"}),D]},D))})]}),e.jsxs("div",{className:"flex flex-col gap-2 min-w-[160px]",children:[e.jsxs(_,{size:"lg",onClick:ce,children:[e.jsx(na,{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(ei,{className:`w-4 h-4 mr-2 ${h?"fill-current":""}`}),h?"已点赞":"点赞"]})]})]}),e.jsx(la,{}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsx(Te,{children:e.jsxs(ze,{className:"flex items-center gap-3 py-4",children:[e.jsx(Hl,{className:"w-8 h-8 text-blue-500 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:r.providers.length}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"API 提供商"})]})]})}),e.jsx(Te,{children:e.jsxs(ze,{className:"flex items-center gap-3 py-4",children:[e.jsx(Wn,{className:"w-8 h-8 text-green-500 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:r.models.length}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"模型配置"})]})]})}),e.jsx(Te,{children:e.jsxs(ze,{className:"flex items-center gap-3 py-4",children:[e.jsx(er,{className:"w-8 h-8 text-purple-500 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:Object.keys(r.task_config).length}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"任务配置"})]})]})})]}),e.jsxs(Jt,{defaultValue:"providers",className:"space-y-4",children:[e.jsxs(Gt,{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(Hl,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"提供商"}),e.jsx("span",{className:"sm:hidden",children:"提供商"}),e.jsxs("span",{className:"hidden sm:inline",children:["(",r.providers.length,")"]})]}),e.jsxs(Xe,{value:"models",className:"gap-1 sm:gap-2",children:[e.jsx(Wn,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"模型"}),e.jsx("span",{className:"sm:hidden",children:"模型"}),e.jsxs("span",{className:"hidden sm:inline",children:["(",r.models.length,")"]})]}),e.jsxs(Xe,{value:"tasks",className:"gap-1 sm:gap-2",children:[e.jsx(er,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"任务配置"}),e.jsx("span",{className:"sm:hidden",children:"任务"}),e.jsxs("span",{className:"hidden sm:inline",children:["(",Object.keys(r.task_config).length,")"]})]})]}),e.jsx(Ss,{value:"providers",children:e.jsxs(Te,{children:[e.jsxs(Oe,{children:[e.jsx(Ue,{children:"API 提供商"}),e.jsx(Ns,{children:"模板中包含的 API 提供商配置(不含 API Key)"})]}),e.jsx(ze,{children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(ql,{children:[e.jsx(Vl,{children:e.jsxs(_t,{children:[e.jsx(ns,{children:"名称"}),e.jsx(ns,{children:"Base URL"}),e.jsx(ns,{children:"类型"})]})}),e.jsx(Gl,{children:r.providers.map(D=>e.jsxs(_t,{children:[e.jsx(Ze,{className:"font-medium whitespace-nowrap",children:D.name}),e.jsx(Ze,{className:"text-muted-foreground font-mono text-sm max-w-[200px] truncate",children:D.base_url}),e.jsx(Ze,{children:e.jsx(Ce,{variant:"outline",children:D.client_type})})]},D.name))})]})})})]})}),e.jsx(Ss,{value:"models",children:e.jsxs(Te,{children:[e.jsxs(Oe,{children:[e.jsx(Ue,{children:"模型配置"}),e.jsx(Ns,{children:"模板中包含的模型配置"})]}),e.jsx(ze,{children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(ql,{children:[e.jsx(Vl,{children:e.jsxs(_t,{children:[e.jsx(ns,{children:"模型名称"}),e.jsx(ns,{children:"标识符"}),e.jsx(ns,{children:"提供商"}),e.jsx(ns,{className:"text-right",children:"价格 (入/出)"})]})}),e.jsx(Gl,{children:r.models.map(D=>e.jsxs(_t,{children:[e.jsx(Ze,{className:"font-medium whitespace-nowrap",children:D.name}),e.jsx(Ze,{className:"text-muted-foreground font-mono text-sm max-w-[150px] truncate",children:D.model_identifier}),e.jsx(Ze,{className:"whitespace-nowrap",children:D.api_provider}),e.jsxs(Ze,{className:"text-right text-muted-foreground whitespace-nowrap",children:["¥",D.price_in," / ¥",D.price_out]})]},D.name))})]})})})]})}),e.jsx(Ss,{value:"tasks",children:e.jsxs(Te,{children:[e.jsxs(Oe,{children:[e.jsx(Ue,{children:"任务配置"}),e.jsx(Ns,{children:"模板中各任务类型的模型分配"})]}),e.jsx(ze,{children:e.jsx(Z5,{type:"multiple",className:"w-full",children:Object.entries(r.task_config).map(([D,Q])=>e.jsxs(Ob,{value:D,children:[e.jsx(Lb,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Sn,{className:"w-4 h-4"}),W5[D]||D,e.jsxs(Ce,{variant:"secondary",className:"ml-2",children:[Q.model_list.length," 个模型"]})]})}),e.jsx(Ub,{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:Q.model_list.map(B=>e.jsx(Ce,{variant:"outline",children:B},B))}),Q.temperature!==void 0&&e.jsxs("div",{className:"text-sm",children:["Temperature: ",e.jsx("span",{className:"font-mono",children:Q.temperature})]}),Q.max_tokens!==void 0&&e.jsxs("div",{className:"text-sm",children:["Max Tokens: ",e.jsx("span",{className:"font-mono",children:Q.max_tokens})]})]})})]},D))})})]})})]}),e.jsx(sT,{open:N,onOpenChange:j,pack:r,step:b,setStep:y,conflicts:w,detectingConflicts:M,applying:F,options:C,setOptions:R,_providerMapping:H,_setProviderMapping:O,newProviderApiKeys:X,setNewProviderApiKeys:L,onApply:ge})]})})}):e.jsxs("div",{className:"text-center py-12",children:[e.jsx(xa,{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:()=>l({to:"/config/pack-market"}),children:[e.jsx($a,{className:"w-4 h-4 mr-2"}),"返回市场"]})]})}function sT({open:a,onOpenChange:l,pack:r,step:c,setStep:d,conflicts:m,detectingConflicts:h,applying:f,options:p,setOptions:g,_providerMapping:N,_setProviderMapping:j,newProviderApiKeys:b,setNewProviderApiKeys:y,onApply:w}){return e.jsx(Qs,{open:a,onOpenChange:l,children:e.jsxs(Hs,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(qs,{children:[e.jsxs(Vs,{className:"flex items-center gap-2",children:[e.jsx(xa,{className:"w-5 h-5"}),"应用配置模板"]}),e.jsxs(at,{children:["步骤 ",c," / ",3,":",c===1&&"选择要应用的内容",c===2&&"配置提供商映射",c===3&&"确认并应用"]})]}),h?e.jsxs("div",{className:"py-8 text-center",children:[e.jsx(Fs,{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(tt,{id:"apply_providers",checked:p.apply_providers,onCheckedChange:M=>g({...p,apply_providers:M})}),e.jsxs(T,{htmlFor:"apply_providers",className:"flex items-center gap-2",children:[e.jsx(Hl,{className:"w-4 h-4"}),"应用提供商配置 (",r.providers.length," 个)"]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(tt,{id:"apply_models",checked:p.apply_models,onCheckedChange:M=>g({...p,apply_models:M})}),e.jsxs(T,{htmlFor:"apply_models",className:"flex items-center gap-2",children:[e.jsx(Wn,{className:"w-4 h-4"}),"应用模型配置 (",r.models.length," 个)"]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(tt,{id:"apply_task_config",checked:p.apply_task_config,onCheckedChange:M=>g({...p,apply_task_config:M})}),e.jsxs(T,{htmlFor:"apply_task_config",className:"flex items-center gap-2",children:[e.jsx(er,{className:"w-4 h-4"}),"应用任务配置 (",Object.keys(r.task_config).length," 个)"]})]})]}),p.apply_task_config&&e.jsxs("div",{className:"pl-6 space-y-2 border-l-2 border-muted",children:[e.jsx(T,{className:"text-sm font-medium",children:"任务配置应用模式"}),e.jsxs(Rx,{value:p.task_mode,onValueChange:M=>g({...p,task_mode:M}),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Wo,{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(Wo,{value:"replace",id:"mode_replace"}),e.jsx(T,{htmlFor:"mode_replace",className:"font-normal",children:"替换模式 - 用模板配置完全替换现有配置"})]})]})]})]}),c===2&&m&&e.jsxs("div",{className:"space-y-4",children:[p.apply_providers&&m.existing_providers.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs(ht,{children:[e.jsx(Yt,{className:"h-4 w-4"}),e.jsx(Jn,{children:"发现已有的提供商"}),e.jsx(ft,{children:"以下提供商的 URL 与您本地配置中的提供商匹配,将自动使用本地提供商:"})]}),e.jsx("div",{className:"space-y-2",children:m.existing_providers.map(({pack_provider:M,local_providers:S})=>e.jsxs("div",{className:"flex items-center gap-2 p-3 bg-muted rounded-lg",children:[e.jsx(Ot,{className:"w-4 h-4 text-green-500 flex-shrink-0"}),e.jsx("span",{className:"font-medium flex-shrink-0",children:M.name}),e.jsx(ra,{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(Ce,{variant:"outline",className:"ml-auto",children:"URL 匹配"})]}):e.jsxs(e.Fragment,{children:[e.jsxs(Pe,{value:N[M.name]||S[0].name,onValueChange:F=>j({...N,[M.name]:F}),children:[e.jsx(Be,{className:"w-[200px]",children:e.jsx(Fe,{})}),e.jsx(Ie,{children:S.map(F=>e.jsx(W,{value:F.name,children:F.name},F.name))})]}),e.jsxs(Ce,{variant:"outline",className:"ml-auto",children:[S.length," 个匹配"]})]})]},M.name))})]}),p.apply_providers&&m.new_providers.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs(ht,{variant:"destructive",children:[e.jsx(Lt,{className:"h-4 w-4"}),e.jsx(Jn,{children:"需要配置 API Key"}),e.jsx(ft,{children:"以下提供商在您的本地配置中不存在,需要填写 API Key:"})]}),e.jsx("div",{className:"space-y-4",children:m.new_providers.map(M=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(cx,{className:"w-4 h-4 text-amber-500"}),e.jsx("span",{className:"font-medium",children:M.name}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",M.base_url,")"]})]}),e.jsx(ne,{type:"password",placeholder:`输入 ${M.name} 的 API Key`,value:b[M.name]||"",onChange:S=>y({...b,[M.name]:S.target.value})})]},M.name))})]}),(!p.apply_providers||m.existing_providers.length===0&&m.new_providers.length===0)&&e.jsxs(ht,{children:[e.jsx(Ot,{className:"h-4 w-4"}),e.jsx(Jn,{children:"无需配置"}),e.jsx(ft,{children:"模板中没有提供商配置,或您选择不应用提供商。"})]})]}),c===3&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(ht,{children:[e.jsx(Yt,{className:"h-4 w-4"}),e.jsx(Jn,{children:"确认应用"}),e.jsx(ft,{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(Ot,{className:"w-4 h-4 text-green-500"}),e.jsx(Hl,{className:"w-4 h-4"}),e.jsxs("span",{children:["应用 ",r.providers.length," 个提供商配置"]})]}),p.apply_models&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Ot,{className:"w-4 h-4 text-green-500"}),e.jsx(Wn,{className:"w-4 h-4"}),e.jsxs("span",{children:["应用 ",r.models.length," 个模型配置"]})]}),p.apply_task_config&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Ot,{className:"w-4 h-4 text-green-500"}),e.jsx(er,{className:"w-4 h-4"}),e.jsxs("span",{children:[p.task_mode==="append"?"追加":"替换"," ",Object.keys(r.task_config).length," 个任务配置"]})]})]}),m&&m.new_providers.length>0&&e.jsxs(ht,{variant:"destructive",children:[e.jsx(Lt,{className:"h-4 w-4"}),e.jsxs(ft,{children:["将添加 ",m.new_providers.length," 个新提供商,请确保已填写正确的 API Key。"]})]})]})]}),e.jsxs(gt,{className:"flex justify-between",children:[e.jsx("div",{children:c>1&&!h&&e.jsx(_,{variant:"outline",onClick:()=>d(c-1),disabled:f,children:"上一步"})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(_,{variant:"outline",onClick:()=>l(!1),disabled:f,children:"取消"}),c<3?e.jsx(_,{onClick:()=>d(c+1),disabled:h,children:"下一步"}):e.jsxs(_,{onClick:w,disabled:f,children:[f&&e.jsx(Fs,{className:"w-4 h-4 mr-2 animate-spin"}),"应用模板"]})]})]})]})})}function tT(){return e.jsx("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:e.jsx(ts,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsx(ks,{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(ks,{className:"w-10 h-10"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(ks,{className:"h-8 w-2/3"}),e.jsx(ks,{className:"h-4 w-full"})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-4",children:[e.jsx(ks,{className:"h-4 w-24"}),e.jsx(ks,{className:"h-4 w-32"}),e.jsx(ks,{className:"h-4 w-28"}),e.jsx(ks,{className:"h-4 w-20"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(ks,{className:"h-6 w-20"}),e.jsx(ks,{className:"h-6 w-24"}),e.jsx(ks,{className:"h-6 w-16"})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 min-w-[160px]",children:[e.jsx(ks,{className:"h-10 w-full"}),e.jsx(ks,{className:"h-10 w-full"})]})]}),e.jsx(ks,{className:"h-px w-full"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsx(ks,{className:"h-24"}),e.jsx(ks,{className:"h-24"}),e.jsx(ks,{className:"h-24"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ks,{className:"h-10 w-32"}),e.jsx(ks,{className:"h-10 w-32"}),e.jsx(ks,{className:"h-10 w-32"})]}),e.jsx(ks,{className:"h-96 w-full"})]})]})})})}function aT(){const a=ha(),[l,r]=u.useState(!0);return u.useEffect(()=>{let c=!1;return(async()=>{try{const m=await dc();!c&&!m&&a({to:"/auth"})}catch{c||a({to:"/auth"})}finally{c||r(!1)}})(),()=>{c=!0}},[a]),{checking:l}}async function lT(){return await dc()}const nT=ti("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"}}),$b=u.forwardRef(({className:a,size:l,abbrTitle:r,children:c,...d},m)=>e.jsx("kbd",{className:P(nT({size:l,className:a})),ref:m,...d,children:r?e.jsx("abbr",{title:r,children:c}):c}));$b.displayName="Kbd";const rT=[{icon:id,title:"首页",description:"查看仪表板概览",path:"/",category:"概览"},{icon:Ua,title:"麦麦主程序配置",description:"配置麦麦的核心设置",path:"/config/bot",category:"配置"},{icon:Hl,title:"麦麦模型提供商配置",description:"配置模型提供商",path:"/config/modelProvider",category:"配置"},{icon:gv,title:"麦麦模型配置",description:"配置模型参数",path:"/config/model",category:"配置"},{icon:rd,title:"表情包管理",description:"管理麦麦的表情包",path:"/resource/emoji",category:"资源"},{icon:Ia,title:"表达方式管理",description:"管理麦麦的表达方式",path:"/resource/expression",category:"资源"},{icon:jv,title:"人物信息管理",description:"管理人物信息",path:"/resource/person",category:"资源"},{icon:Wr,title:"黑话管理",description:"管理麦麦学习到的黑话和俚语",path:"/resource/jargon",category:"资源"},{icon:t_,title:"统计信息",description:"查看使用统计",path:"/statistics",category:"监控"},{icon:xa,title:"插件市场",description:"浏览和安装插件",path:"/plugins",category:"扩展"},{icon:ux,title:"日志查看器",description:"查看系统日志",path:"/logs",category:"监控"},{icon:Sn,title:"系统设置",description:"配置系统参数",path:"/settings",category:"系统"}];function iT({open:a,onOpenChange:l}){const[r,c]=u.useState(""),[d,m]=u.useState(0),h=ha(),f=rT.filter(N=>N.title.toLowerCase().includes(r.toLowerCase())||N.description.toLowerCase().includes(r.toLowerCase())||N.category.toLowerCase().includes(r.toLowerCase())),p=u.useCallback(N=>{h({to:N}),l(!1),c(""),m(0)},[h,l]),g=u.useCallback(N=>{N.key==="ArrowDown"?(N.preventDefault(),m(j=>(j+1)%f.length)):N.key==="ArrowUp"?(N.preventDefault(),m(j=>(j-1+f.length)%f.length)):N.key==="Enter"&&f[d]&&(N.preventDefault(),p(f[d].path))},[f,d,p]);return e.jsx(Qs,{open:a,onOpenChange:l,children:e.jsxs(Hs,{className:"max-w-2xl p-0 gap-0",children:[e.jsxs(qs,{className:"px-4 pt-4 pb-0",children:[e.jsx(Vs,{className:"sr-only",children:"搜索"}),e.jsxs("div",{className:"relative",children:[e.jsx($t,{className:"absolute left-3 top-1/2 h-5 w-5 -translate-y-1/2 text-muted-foreground"}),e.jsx(ne,{value:r,onChange:N=>{c(N.target.value),m(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(ts,{className:"h-[400px]",children:f.length>0?e.jsx("div",{className:"p-2",children:f.map((N,j)=>{const b=N.icon;return e.jsxs("button",{onClick:()=>p(N.path),onMouseEnter:()=>m(j),className:P("w-full flex items-center gap-3 px-3 py-2.5 rounded-md text-left transition-colors",j===d?"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($t,{className:"h-12 w-12 text-muted-foreground/50 mb-4"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:r?"未找到匹配的页面":"输入关键词开始搜索"})]})})}),e.jsx("div",{className:"border-t px-4 py-3 flex items-center justify-between text-xs text-muted-foreground",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"↑"}),e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"↓"}),"导航"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"Enter"}),"选择"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"Esc"}),"关闭"]})]})})]})})}function cT(){const a=window.location.protocol==="http:",l=window.location.hostname.toLowerCase(),r=l==="localhost"||l==="127.0.0.1"||l==="::1",c=sessionStorage.getItem("http-warning-dismissed")==="true",[d,m]=u.useState(a&&!r&&!c),[h,f]=u.useState(!1),p=()=>{f(!0),m(!1),sessionStorage.setItem("http-warning-dismissed","true")};return!d||h?null:e.jsx("div",{className:"relative bg-amber-500/10 border-b border-amber-500/20 backdrop-blur-sm",children:e.jsx("div",{className:"container mx-auto px-4 py-3",children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1",children:[e.jsx(Lt,{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(Sa,{className:"h-4 w-4"})})]})})})}function oT(){const[a,l]=u.useState(0),[r,c]=u.useState(!1),d=u.useRef(null);u.useEffect(()=>{const g=N=>{const j=N.target;if(j.scrollHeight>j.clientHeight+100){d.current=j;const b=j.scrollTop,y=j.scrollHeight-j.clientHeight,w=y>0?b/y*100:0;l(w),c(b>300)}};return window.addEventListener("scroll",g,{capture:!0,passive:!0}),()=>window.removeEventListener("scroll",g,{capture:!0})},[]);const m=()=>{d.current?.scrollTo({top:0,behavior:"smooth"})},h=18,f=2*Math.PI*h,p=f-a/100*f;return e.jsx("div",{className:P("fixed bottom-24 right-8 z-50 transition-all duration-500 ease-in-out transform",r?"translate-x-0 opacity-100":"translate-x-32 opacity-0 pointer-events-none"),children:e.jsxs(_,{variant:"outline",size:"icon",className: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:m,"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(a_,{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"})]})})}function dT({children:a}){const{checking:l}=aT(),[r,c]=u.useState(!0),[d,m]=u.useState(!1),[h,f]=u.useState(!1),[p,g]=u.useState(!1),{theme:N,setTheme:j}=vx(),b=nw();if(u.useEffect(()=>{if(r)g(!1);else{const S=setTimeout(()=>{g(!0)},350);return()=>clearTimeout(S)}},[r]),u.useEffect(()=>{const S=F=>{(F.metaKey||F.ctrlKey)&&F.key==="k"&&(F.preventDefault(),f(!0))};return window.addEventListener("keydown",S),()=>window.removeEventListener("keydown",S)},[]),l)return e.jsx("div",{className:"flex h-screen items-center justify-center bg-background",children:e.jsx("div",{className:"text-muted-foreground",children:"正在验证登录状态..."})});const y=[{title:"概览",items:[{icon:id,label:"首页",path:"/"}]},{title:"麦麦配置编辑",items:[{icon:Ua,label:"麦麦主程序配置",path:"/config/bot"},{icon:Hl,label:"AI模型厂商配置",path:"/config/modelProvider",tourId:"sidebar-model-provider"},{icon:gv,label:"模型管理与分配",path:"/config/model",tourId:"sidebar-model-management"},{icon:zg,label:"麦麦适配器配置",path:"/config/adapter"}]},{title:"麦麦资源管理",items:[{icon:rd,label:"表情包管理",path:"/resource/emoji"},{icon:Ia,label:"表达方式管理",path:"/resource/expression"},{icon:Wr,label:"黑话管理",path:"/resource/jargon"},{icon:jv,label:"人物信息管理",path:"/resource/person"},{icon:xv,label:"知识库图谱可视化",path:"/resource/knowledge-graph"},{icon:Zr,label:"麦麦知识库管理",path:"/resource/knowledge-base"}]},{title:"扩展与监控",items:[{icon:xa,label:"插件市场",path:"/plugins"},{icon:fv,label:"配置模板市场",path:"/config/pack-market"},{icon:zg,label:"插件配置",path:"/plugin-config"},{icon:ux,label:"日志查看器",path:"/logs"},{icon:nx,label:"计划器&回复器监控",path:"/planner-monitor"},{icon:Ia,label:"本地聊天室",path:"/chat"}]},{title:"系统",items:[{icon:Sn,label:"系统设置",path:"/settings"}]}],z=N==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":N,M=async()=>{await B_()};return e.jsx(Zv,{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",r?"lg:w-64":"lg:w-16",d?"translate-x-0":"-translate-x-full lg:translate-x-0"),children:[e.jsx("div",{className:"flex h-16 items-center border-b px-4",children:e.jsxs("div",{className:P("relative flex items-center justify-center flex-1 transition-all overflow-hidden","lg:flex-1",!r&&"lg:flex-none lg:w-8"),children:[e.jsxs("div",{className:P("flex items-baseline gap-2",!r&&"lg:hidden"),children:[e.jsx("span",{className:"font-bold text-xl text-primary-gradient whitespace-nowrap",children:"MaiBot WebUI"}),e.jsx("span",{className:"text-xs text-primary/60 whitespace-nowrap",children:v2()})]}),!r&&e.jsx("span",{className:"hidden lg:block font-bold text-primary-gradient text-2xl",children:"M"})]})}),e.jsx(ts,{className:P("flex-1 overflow-x-hidden",!r&&"lg:w-16"),children:e.jsx("nav",{className:P("p-4",!r&&"lg:p-2 lg:w-16"),children:e.jsx("ul",{className:P("space-y-6",!r&&"lg:space-y-3 lg:w-full"),children:y.map((S,F)=>e.jsxs("li",{children:[e.jsx("div",{className:P("px-3 h-[1.25rem]","mb-2",!r&&"lg:mb-1 lg:invisible"),children:e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground/60 whitespace-nowrap",children:S.title})}),!r&&F>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}),R=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",r?"gap-3":"gap-3 lg:gap-0"),children:[e.jsx(R,{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",r?"opacity-100 max-w-[200px]":"opacity-100 max-w-[200px] lg:opacity-0 lg:max-w-0 lg:overflow-hidden"),children:E.label})]})]});return e.jsx("li",{className:"relative",children:e.jsxs(Wv,{children:[e.jsx(eN,{asChild:!0,children:e.jsx(Kn,{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",r?"px-3":"px-3 lg:px-0 lg:justify-center lg:w-12 lg:mx-auto"),onClick:()=>m(!1),children:H})}),p&&e.jsx(Tx,{side:"right",className:"hidden lg:block",children:e.jsx("p",{children:E.label})})]})},E.path)})})]},S.title))})})})]}),d&&e.jsx("div",{className:"fixed inset-0 z-40 bg-black/50 lg:hidden",onClick:()=>m(!1)}),e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsx(cT,{}),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:()=>m(!d),className:"rounded-lg p-2 hover:bg-accent lg:hidden",children:e.jsx(l_,{className:"h-5 w-5"})}),e.jsx("button",{onClick:()=>c(!r),className:"hidden rounded-lg p-2 hover:bg-accent lg:block",title:r?"收起侧边栏":"展开侧边栏",children:e.jsx(Pa,{className:P("h-5 w-5 transition-transform",!r&&"rotate-180")})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Kn,{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(n_,{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($t,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"搜索..."}),e.jsxs($b,{size:"sm",className:"absolute right-2 top-1/2 -translate-y-1/2",children:[e.jsx("span",{className:"text-xs",children:"⌘"}),"K"]})]}),e.jsx(iT,{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(r_,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"麦麦文档"})]}),e.jsx("button",{onClick:S=>{h2(z==="dark"?"light":"dark",j,S)},className:"rounded-lg p-2 hover:bg-accent",title:z==="dark"?"切换到浅色模式":"切换到深色模式",children:z==="dark"?e.jsx(ix,{className:"h-5 w-5"}):e.jsx(tc,{className:"h-5 w-5"})}),e.jsx("div",{className:"h-6 w-px bg-border"}),e.jsxs(_,{variant:"ghost",size:"sm",onClick:M,className:"gap-2",title:"登出系统",children:[e.jsx(i_,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"登出"})]})]})]}),e.jsx("main",{className:"flex-1 overflow-hidden bg-background",children:a}),e.jsx(oT,{})]})]})})}function uT(a){const l=a.split(` `).slice(1),r=[];for(const c of l){const d=c.trim();if(!d.startsWith("at "))continue;const m=d.match(/at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?$/);m?r.push({functionName:m[1]||"",fileName:m[2],lineNumber:m[3],columnNumber:m[4],raw:d}):r.push({functionName:"",fileName:"",lineNumber:"",columnNumber:"",raw:d})}return r}function mT({error:a,errorInfo:l}){const[r,c]=u.useState(!0),[d,m]=u.useState(!1),[h,f]=u.useState(!1),p=a.stack?uT(a.stack):[],g=async()=>{const N=` Error: ${a.name} Message: ${a.message}