Files
WebAI2API/webui/dist/assets/workers.js
T

2 lines
13 KiB
JavaScript

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