mirror of
https://github.com/foxhui/WebAI2API.git
synced 2026-06-16 21:03:59 +08:00
2 lines
14 KiB
JavaScript
2 lines
14 KiB
JavaScript
import{k as re,n as D,o as ie,r as _,b as W,d as i,w as s,c as n,g as t,f as r,h as v,j as d,e as x,t as g,F as z,p as pe}from"./index.js";const ue={style:{"margin-bottom":"24px"}},de={style:{"margin-bottom":"24px"}},ve={style:{"margin-bottom":"24px"}},me={style:{"margin-bottom":"8px"}},ye={style:{"margin-bottom":"8px"}},xe={style:{display:"flex","justify-content":"flex-end","margin-top":"24px"}},ge={style:{display:"flex","justify-content":"space-between","align-items":"center"}},fe={key:0},ke={key:3},we=["onClick"],be=["onClick"],_e={style:{"margin-bottom":"24px"}},Ce={style:{"margin-bottom":"16px"}},Me={style:{"margin-bottom":"16px"}},ce={style:{"margin-bottom":"16px"}},Ue={style:{"margin-bottom":"16px"}},Te={style:{"margin-left":"8px"}},he={key:0,style:{"margin-bottom":"16px"}},Pe={key:1,style:{"margin-bottom":"16px"}},De={key:2,style:{"margin-bottom":"16px"}},Ae={key:3,style:{"margin-bottom":"16px"}},Se={style:{"margin-left":"8px"}},We={key:4,style:{"margin-bottom":"16px"}},ze={key:5,style:{"margin-bottom":"16px"}},$e={style:{display:"flex","justify-content":"space-between","align-items":"center","margin-bottom":"8px"}},Ie=["onClick"],Ne=["onClick"],He={style:{"font-weight":"600"}},je={style:{"font-size":"12px",color:"#8c8c8c"}},Fe={key:0},Oe={key:0},Ve={style:{"text-align":"right"}},Be={style:{"margin-bottom":"16px"}},Ee={style:{"margin-bottom":"16px"}},Le={style:{"margin-bottom":"16px"}},Re={style:{"margin-bottom":"16px"}},Ge={__name:"workers",setup(Ke){const u=re(),m=D({get:()=>u.poolConfig,set:a=>u.poolConfig=a}),F=async()=>{await u.savePoolConfig(m.value)};ie(async()=>{await Promise.all([u.fetchWorkerConfig(),u.fetchPoolConfig(),u.fetchAdaptersMeta()])});const O=D(()=>{const a=u.adaptersMeta.map(e=>({label:e.displayName||e.id,value:e.id}));return a.find(e=>e.value==="merge")||a.unshift({label:"Merge(聚合模式)",value:"merge"}),a}),V=D(()=>u.adaptersMeta.filter(a=>a.id!=="merge").map(a=>({label:a.displayName||a.id,value:a.id}))),h=a=>a==="merge"?"Merge(聚合模式)":u.adaptersMeta.find(k=>k.id===a)?.displayName||a,B=[{title:"实例名称",dataIndex:"name",key:"name"},{title:"Worker 数量",dataIndex:"workerCount",key:"workerCount"},{title:"代理",dataIndex:"proxy",key:"proxy"},{title:"数据标记",key:"userDataMark",dataIndex:"userDataMark"},{title:"操作",key:"action"}],P=D({get:()=>u.workerConfig,set:a=>{u.workerConfig=a}}),w=_(!1),f=_(null),l=_({name:"",userDataMark:"",proxy:!1,proxyType:"socks5",proxyHost:"",proxyPort:1080,proxyAuth:!1,proxyUsername:"",proxyPassword:"",workers:[]}),E=()=>{f.value=null;const a=Math.random().toString(36).substring(2,7);l.value={name:`instance-${(P.value||[]).length+1}-${a}`,userDataMark:"",proxy:!1,proxyType:"socks5",proxyHost:"",proxyPort:1080,proxyAuth:!1,proxyUsername:"",proxyPassword:"",workers:[]},w.value=!0},L=a=>{f.value=a,l.value={name:a.name,userDataMark:a.userDataMark||"",proxy:!!a.proxy,proxyType:a.proxy?.type||"socks5",proxyHost:a.proxy?.host||"",proxyPort:a.proxy?.port||1080,proxyAuth:a.proxy?.auth||!1,proxyUsername:a.proxy?.username||"",proxyPassword:a.proxy?.password||"",workers:a.workers?[...a.workers]:[]},(a.proxy===null||a.proxy===void 0)&&(l.value.proxy=!1),w.value=!0},R=async a=>{const e=P.value.filter(k=>k.id!==a.id);await u.saveWorkerConfig(e)},K=async()=>{const a={id:f.value?f.value.id:`inst_${Date.now()}`,name:l.value.name,userDataMark:l.value.userDataMark,workers:l.value.workers,proxy:l.value.proxy?{enable:!0,type:l.value.proxyType,host:l.value.proxyHost,port:l.value.proxyPort,auth:l.value.proxyAuth,username:l.value.proxyUsername,password:l.value.proxyPassword}:null};let e=[...P.value||[]];if(f.value===null)e.push(a);else{const b=e.findIndex(c=>c.id===f.value.id);b>-1&&(e[b]=a)}await u.saveWorkerConfig(e)&&(w.value=!1)},C=_(-1),M=_(!1),p=_({name:"",type:"lmarena",mergeTypes:[],mergeMonitor:""}),q=()=>{C.value=-1;const a=Math.random().toString(36).substring(2,7);p.value={name:`worker-${l.value.workers.length+1}-${a}`,type:"lmarena",mergeTypes:[],mergeMonitor:""},M.value=!0},G=a=>{C.value=a;const e=l.value.workers[a];p.value={name:e.name,type:e.type,mergeTypes:e.mergeTypes?[...e.mergeTypes]:[],mergeMonitor:e.mergeMonitor||""},M.value=!0},J=()=>{C.value===-1?l.value.workers.push({...p.value}):l.value.workers[C.value]={...p.value},M.value=!1},Q=a=>{l.value.workers.splice(a,1)};return(a,e)=>{const k=r("a-segmented"),b=r("a-input-number"),c=r("a-switch"),$=r("a-col"),X=r("a-row"),I=r("a-collapse-panel"),N=r("a-collapse"),U=r("a-button"),H=r("a-card"),Y=r("a-tag"),Z=r("a-divider"),ee=r("a-table"),T=r("a-input"),te=r("a-input-password"),oe=r("a-list-item"),le=r("a-list"),ae=r("a-drawer"),A=r("a-select"),j=r("a-select-option"),ne=r("a-modal"),se=r("a-layout");return i(),W(se,{style:{background:"transparent"}},{default:s(()=>[n(H,{title:"负载均衡",bordered:!1,style:{width:"100%","margin-bottom":"10px"}},{default:s(()=>[t("div",ue,[e[20]||(e[20]=t("div",{style:{"font-weight":"600","margin-bottom":"8px"}},"调度策略",-1)),e[21]||(e[21]=t("div",{style:{"font-size":"12px",color:"#8c8c8c","margin-bottom":"12px"}}," 选择任务分配到工作实例的调度算法 ",-1)),n(k,{value:m.value.strategy,"onUpdate:value":e[0]||(e[0]=o=>m.value.strategy=o),block:"",options:[{label:"最少繁忙",value:"least_busy"},{label:"轮询",value:"round_robin"},{label:"随机",value:"random"}]},null,8,["value"])]),t("div",de,[e[23]||(e[23]=t("div",{style:{"font-weight":"600","margin-bottom":"8px"}},"生成等待超时",-1)),e[24]||(e[24]=t("div",{style:{"font-size":"12px",color:"#8c8c8c","margin-bottom":"12px"}}," 等待 AI 生成结果的最长时间,单位:秒(默认 120 秒) ",-1)),n(b,{value:m.value.waitTimeout,"onUpdate:value":e[1]||(e[1]=o=>m.value.waitTimeout=o),min:30,max:3600,step:30,style:{width:"100%"},placeholder:"请输入超时秒数"},{addonAfter:s(()=>[...e[22]||(e[22]=[v("秒",-1)])]),_:1},8,["value"])]),t("div",ve,[n(N,null,{default:s(()=>[n(I,{key:"failover",header:"故障转移"},{default:s(()=>[n(X,{gutter:16},{default:s(()=>[n($,{xs:24,md:12},{default:s(()=>[t("div",me,[e[25]||(e[25]=t("div",{style:{"font-weight":"600","margin-bottom":"8px"}},"启用故障转移",-1)),e[26]||(e[26]=t("div",{style:{"font-size":"12px",color:"#8c8c8c","margin-bottom":"12px"}}," 启用后,任务失败时会自动切换到其他可用实例重试 ",-1)),n(c,{checked:m.value.failover.enabled,"onUpdate:checked":e[2]||(e[2]=o=>m.value.failover.enabled=o)},null,8,["checked"])])]),_:1}),n($,{xs:24,md:12},{default:s(()=>[t("div",ye,[e[27]||(e[27]=t("div",{style:{"font-weight":"600","margin-bottom":"8px"}},"重试次数",-1)),e[28]||(e[28]=t("div",{style:{"font-size":"12px",color:"#8c8c8c","margin-bottom":"12px"}}," 故障转移时最大重试次数,范围 1-10 ",-1)),n(b,{value:m.value.failover.maxRetries,"onUpdate:value":e[3]||(e[3]=o=>m.value.failover.maxRetries=o),min:1,max:10,disabled:!m.value.failover.enabled,style:{width:"100%"},placeholder:"请输入重试次数"},null,8,["value","disabled"])])]),_:1})]),_:1})]),_:1})]),_:1})]),t("div",xe,[n(U,{type:"primary",onClick:F},{default:s(()=>[...e[29]||(e[29]=[v(" 保存设置 ",-1)])]),_:1})])]),_:1}),n(H,{bordered:!1,style:{width:"100%"}},{title:s(()=>[t("div",ge,[e[31]||(e[31]=t("span",null,"实例列表",-1)),n(U,{type:"primary",onClick:E},{default:s(()=>[...e[30]||(e[30]=[v(" 创建实例 ",-1)])]),_:1})])]),default:s(()=>[n(ee,{columns:B,"data-source":P.value,pagination:!1},{bodyCell:s(({column:o,record:y})=>[o.key==="name"?(i(),d("a",fe,g(y.name),1)):o.key==="workerCount"?(i(),d(z,{key:1},[v(g(y.workers?y.workers.length:0),1)],64)):o.key==="proxy"?(i(),W(Y,{key:2,color:y.proxy?"green":"default"},{default:s(()=>[v(g(y.proxy?"已启用":"未启用"),1)]),_:2},1032,["color"])):o.key==="action"?(i(),d("span",ke,[t("a",{onClick:S=>L(y)},"编辑",8,we),n(Z,{type:"vertical"}),t("a",{style:{color:"#ff4d4f"},onClick:S=>R(y)},"删除",8,be)])):x("",!0)]),_:1},8,["data-source"])]),_:1}),n(ae,{open:w.value,"onUpdate:open":e[14]||(e[14]=o=>w.value=o),title:f.value===null?"创建实例":`编辑实例 - ${f.value.name}`,placement:"right",width:"500"},{footer:s(()=>[t("div",Ve,[n(U,{style:{"margin-right":"8px"},onClick:e[13]||(e[13]=o=>w.value=!1)},{default:s(()=>[...e[44]||(e[44]=[v("取消",-1)])]),_:1}),n(U,{type:"primary",onClick:K},{default:s(()=>[...e[45]||(e[45]=[v("保存",-1)])]),_:1})])]),default:s(()=>[t("div",_e,[t("div",Ce,[e[32]||(e[32]=t("div",{style:{"font-weight":"600","margin-bottom":"4px"}},"实例名称",-1)),e[33]||(e[33]=t("div",{style:{"font-size":"12px",color:"#ff4d4f","margin-bottom":"8px"}}," * 名称必须全局唯一,不可重复 ",-1)),n(T,{value:l.value.name,"onUpdate:value":e[4]||(e[4]=o=>l.value.name=o),placeholder:"请输入实例名称"},null,8,["value"])]),t("div",Me,[e[34]||(e[34]=t("div",{style:{"font-weight":"600","margin-bottom":"4px"}},"数据标记",-1)),e[35]||(e[35]=t("div",{style:{"font-size":"12px",color:"#8c8c8c","margin-bottom":"8px"}}," 用于区分实例数据存储的文件夹名称 (userDataMark) ",-1)),n(T,{value:l.value.userDataMark,"onUpdate:value":e[5]||(e[5]=o=>l.value.userDataMark=o),placeholder:"请输入数据标记,如: main-gemini"},null,8,["value"])]),t("div",ce,[n(N,null,{default:s(()=>[n(I,{key:"proxy",header:"代理设置"},{default:s(()=>[t("div",Ue,[n(c,{checked:l.value.proxy,"onUpdate:checked":e[6]||(e[6]=o=>l.value.proxy=o)},null,8,["checked"]),t("span",Te,g(l.value.proxy?"已启用代理":"未启用代理"),1)]),l.value.proxy?(i(),d("div",he,[e[36]||(e[36]=t("div",{style:{"font-weight":"600","margin-bottom":"8px"}},"代理类型",-1)),n(k,{value:l.value.proxyType,"onUpdate:value":e[7]||(e[7]=o=>l.value.proxyType=o),block:"",options:[{label:"SOCKS5",value:"socks5"},{label:"HTTP",value:"http"}],style:{width:"100%"}},null,8,["value"])])):x("",!0),l.value.proxy?(i(),d("div",Pe,[e[37]||(e[37]=t("div",{style:{"font-weight":"600","margin-bottom":"8px"}},"服务器地址",-1)),n(T,{value:l.value.proxyHost,"onUpdate:value":e[8]||(e[8]=o=>l.value.proxyHost=o),placeholder:"例如: 127.0.0.1"},null,8,["value"])])):x("",!0),l.value.proxy?(i(),d("div",De,[e[38]||(e[38]=t("div",{style:{"font-weight":"600","margin-bottom":"8px"}},"端口",-1)),n(b,{value:l.value.proxyPort,"onUpdate:value":e[9]||(e[9]=o=>l.value.proxyPort=o),min:1,max:65535,style:{width:"100%"},placeholder:"例如: 1080"},null,8,["value"])])):x("",!0),l.value.proxy?(i(),d("div",Ae,[e[39]||(e[39]=t("div",{style:{"font-weight":"600","margin-bottom":"8px"}},"身份验证",-1)),n(c,{checked:l.value.proxyAuth,"onUpdate:checked":e[10]||(e[10]=o=>l.value.proxyAuth=o)},null,8,["checked"]),t("span",Se,g(l.value.proxyAuth?"需要验证":"无需验证"),1)])):x("",!0),l.value.proxy&&l.value.proxyAuth?(i(),d("div",We,[e[40]||(e[40]=t("div",{style:{"font-weight":"600","margin-bottom":"8px"}},"用户名",-1)),n(T,{value:l.value.proxyUsername,"onUpdate:value":e[11]||(e[11]=o=>l.value.proxyUsername=o),placeholder:"请输入用户名"},null,8,["value"])])):x("",!0),l.value.proxy&&l.value.proxyAuth?(i(),d("div",ze,[e[41]||(e[41]=t("div",{style:{"font-weight":"600","margin-bottom":"8px"}},"密码",-1)),n(te,{value:l.value.proxyPassword,"onUpdate:value":e[12]||(e[12]=o=>l.value.proxyPassword=o),placeholder:"请输入密码"},null,8,["value"])])):x("",!0)]),_:1})]),_:1})]),t("div",null,[t("div",$e,[e[43]||(e[43]=t("div",{style:{"font-weight":"600"}},"Worker 列表",-1)),n(U,{size:"small",type:"primary",onClick:q},{default:s(()=>[...e[42]||(e[42]=[v(" 添加 Worker ",-1)])]),_:1})]),n(le,{bordered:"","data-source":l.value.workers,style:{"margin-top":"8px"}},{renderItem:s(({item:o,index:y})=>[n(oe,null,{actions:s(()=>[t("a",{onClick:S=>G(y)},"编辑",8,Ie),t("a",{style:{color:"#ff4d4f"},onClick:S=>Q(y)},"删除",8,Ne)]),default:s(()=>[t("div",null,[t("div",He,g(o.name),1),t("div",je,[v(" 类型: "+g(h(o.type))+" ",1),o.type==="merge"?(i(),d("span",Fe,[v(" | 聚合: "+g(o.mergeTypes?.map(h).join(", ")||"无")+" ",1),o.mergeMonitor?(i(),d("span",Oe," | 监控: "+g(h(o.mergeMonitor)),1)):x("",!0)])):x("",!0)])])]),_:2},1024)]),_:1},8,["data-source"])])])]),_:1},8,["open","title"]),n(ne,{open:M.value,"onUpdate:open":e[19]||(e[19]=o=>M.value=o),title:C.value===-1?"添加 Worker":"编辑 Worker",okText:"确定",cancelText:"取消",onOk:J},{default:s(()=>[t("div",Be,[e[46]||(e[46]=t("div",{style:{"font-weight":"600","margin-bottom":"4px"}},"Worker 名称",-1)),e[47]||(e[47]=t("div",{style:{"font-size":"12px",color:"#ff4d4f","margin-bottom":"8px"}}," * 名称必须全局唯一,不可重复 ",-1)),n(T,{value:p.value.name,"onUpdate:value":e[15]||(e[15]=o=>p.value.name=o),placeholder:"例如: default"},null,8,["value"])]),t("div",Ee,[e[48]||(e[48]=t("div",{style:{"font-weight":"600","margin-bottom":"8px"}},"适配器类型",-1)),n(A,{value:p.value.type,"onUpdate:value":e[16]||(e[16]=o=>p.value.type=o),style:{width:"100%"},options:O.value},null,8,["value","options"])]),p.value.type==="merge"?(i(),d(z,{key:0},[t("div",Le,[e[49]||(e[49]=t("div",{style:{"font-weight":"600","margin-bottom":"4px"}},"聚合类型",-1)),e[50]||(e[50]=t("div",{style:{"font-size":"12px",color:"#8c8c8c","margin-bottom":"8px"}}," 选择要聚合的后端适配器(可多选) ",-1)),n(A,{value:p.value.mergeTypes,"onUpdate:value":e[17]||(e[17]=o=>p.value.mergeTypes=o),mode:"multiple",style:{width:"100%"},placeholder:"选择要聚合的适配器",options:V.value},null,8,["value","options"])]),t("div",Re,[e[52]||(e[52]=t("div",{style:{"font-weight":"600","margin-bottom":"4px"}},"空闲监控后端",-1)),e[53]||(e[53]=t("div",{style:{"font-size":"12px",color:"#8c8c8c","margin-bottom":"8px"}}," 空闲时挂机监控的后端(可选) ",-1)),n(A,{value:p.value.mergeMonitor,"onUpdate:value":e[18]||(e[18]=o=>p.value.mergeMonitor=o),style:{width:"100%"},placeholder:"选择监控后端(可留空)","allow-clear":""},{default:s(()=>[n(j,{value:""},{default:s(()=>[...e[51]||(e[51]=[v("无",-1)])]),_:1}),(i(!0),d(z,null,pe(p.value.mergeTypes,o=>(i(),W(j,{key:o,value:o},{default:s(()=>[v(g(h(o)),1)]),_:2},1032,["value"]))),128))]),_:1},8,["value"])])],64)):x("",!0)]),_:1},8,["open","title"])]),_:1})}}};export{Ge as default};
|