PageSourceSearch

https://nickz.ai/assets/js/index-Dg_tv8mE.js

js nickz.ai collected 2026-10-05 14:20:06 UTC 144,652 bytes, 1 lines download raw bytes

1import{r as e,j as t,u as s}from"./vendor-react-DejgYtBM.js";import{u as l,a,A as i,s as r,B as n,w as o,O as c,v as d,aS as h,aT as m,aU as p,aV as u,a1 as x,aj as g,N as y,aM as _,Z as f,aW as j}from"./index-BeIIFw6E.js";import{C as v,M as b}from"./channel.constants-BcDm5HEb.js";import{f as w,i as k,z as S,k as C,M as N,j as z,B as T,u as I,v as O,l as A,E,y as R,W as B,p as $,o as M,m as L,A as J,R as P,C as W,Z as D,aQ as F,V,aR as K,H as q,J as U,K as H,F as G,r as Y,a1 as Z,P as X,D as Q,T as ee,a as te}from"./vendor-semi-D8d7bTtM.js";import{R as se,bB as le,T as ae,x as ie,w as re,ag as ne,a7 as oe,n as ce,b as de,bw as he,S as me,ba as pe,bG as ue,U as xe,bH as ge,e as ye,b9 as _e,X as fe,bI as je}from"./vendor-icons-EJvJ5X-w.js";import{u as ve}from"./useTableCompactMode-DWLN7NUj.js";import{G as be}from"./iconBase-SIM2SzwB.js";import{C as we}from"./CardTable-Cq0lqlnD.js";import{V as ke}from"./vendor-charts-CKochBGt.js";import"./vendor-motion-Chfy_MiU.js";import"./useIsMobile-D_kfVI0u.js";const{Text:Se}=w,Ce=[{value:"token",label:"Token"},{value:"video_size",label:"按视频尺寸"},{value:"per_call",label:"按次"},{value:"duration",label:"按秒"},{value:"pixel",label:"按像素"},{value:"step",label:"阶梯"},{value:"free",label:"免费"}],Ne={token:"USD/1M",video_size:"USD/1M",per_call:"USD/次",duration:"USD/秒",pixel:"USD/Mpx",step:"阶梯",free:"免费"},ze=[{key:"prompt_step_cost",label:"Prompt",tip:"base prompt 单价(USD/1M tokens),> 0 必填"},{key:"completion_step_cost",label:"Completion",tip:"completion 单价(USD/1M tokens)"},{key:"cache_step_cost",label:"缓读",tip:"cache_read 单价(0 时回退 Prompt)"},{key:"cache_creation_step_cost",label:"缓写",tip:"cache_creation 单价(Claude 缓写,0 时回退 Prompt)"},{key:"image_step_cost",label:"图像",tip:"多模态图像 token 单价(0 时回退 Prompt)"},{key:"audio_input_step_cost",label:"音频",tip:"Gemini 音频输入单价(0 时不计算)"}],Te=(e,t="token")=>({model_name:e,billing_type:t,cost_config:{input:0,output:0,cache_creation:0,cache_read:0,audio_input:0,audio_output:0,unit_cost:0,steps:[]},dirty:!1}),Ie=({value:e,onChange:s,disabled:l})=>t.jsx(I,{min:0,step:1e-4,precision:4,size:"small",innerButtons:!0,value:e||0,onChange:e=>s(Number(e)||0),disabled:l,style:{width:"100%"}}),Oe=({visible:s,onClose:a,channelId:c,modelName:d,steps:h,onSave:m})=>{const{t:p}=l(),[u,x]=e.useState([]),[g,y]=e.useState(!1);e.useEffect(()=>{s&&x(Array.isArray(h)&&h.length>0?h.map(e=>({step_size:-1,completion_step_size:-1,prompt_step_cost:0,completion_step_cost:0,cache_step_cost:0,cache_creation_step_cost:0,image_step_cost:0,audio_input_step_cost:0,...e})):[])},[s,h]);const _=(e,t)=>{x(s=>s.map((s,l)=>l===e?{...s,...t}:s))};return t.jsxs(B,{visible:s,onCancel:a,title:t.jsxs("span",{children:[p("阶梯成本配置"),d&&t.jsx(k,{color:"blue",size:"small",style:{marginLeft:8},children:d})]}),placement:"right",width:1100,bodyStyle:{padding:16,overflow:"auto"},footer:t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",gap:8},children:[t.jsxs(z,{children:[t.jsx(T,{icon:t.jsx(ie,{size:14}),size:"small",onClick:()=>{x(e=>[...e,{step_size:-1,completion_step_size:-1,prompt_step_cost:0,completion_step_cost:0,cache_step_cost:0,cache_creation_step_cost:0,image_step_cost:0,audio_input_step_cost:0}])},children:p("新增档")}),t.jsx(T,{icon:t.jsx(re,{size:14}),size:"small",type:"tertiary",onClick:async()=>{if(c&&d){y(!0);try{const e=await i.get(`/api/channel/${c}/model-cost-suggest`,{params:{model:d}});if(e?.data?.success){const t=e.data.data?.default_cost_config?.steps;Array.isArray(t)&&t.length>0?(x(t.map(e=>({step_size:-1,completion_step_size:-1,prompt_step_cost:0,completion_step_cost:0,cache_step_cost:0,cache_creation_step_cost:0,image_step_cost:0,audio_input_step_cost:0,...e}))),o(p("已导入 {{n}} 档(来自 global StepRatio)",{n:t.length}))):n(p("该模型在 global StepRatio 中没有阶梯配置"))}else r(e?.data?.message||p("导入失败"))}catch(e){r(e?.message||p("导入失败"))}y(!1)}else r(p("缺少 channel 或 model 上下文"))},loading:g,children:p("按 global StepRatio 一键导入")})]}),t.jsxs(z,{children:[t.jsx(T,{onClick:a,children:p("取消")}),t.jsx(T,{type:"primary",theme:"solid",onClick:()=>{const e=(e=>{if(0===e.length)return p("至少需要一档");let t=-1/0,s=-1/0;for(let l=0;l<e.length;l++){const a=e[l];
1if((a.prompt_step_cost||0)<0||(a.completion_step_cost||0)<0||(a.cache_step_cost||0)<0||(a.cache_creation_step_cost||0)<0||(a.image_step_cost||0)<0||(a.audio_input_step_cost||0)<0)return p("第 {{n}} 档:单价不能为负",{n:l+1});if(a.step_size<=0){if(l!==e.length-1)return p("第 {{n}} 档:兜底档(step_size <= 0)必须放在最后",{n:l+1})}else{if(a.step_size<t)return p("第 {{n}} 档:step_size 必须升序排列",{n:l+1});if(a.step_size===t)if(a.completion_step_size<=0);else{if(s<=0)return p("第 {{n}} 档:同 step_size 下,无限制 completion_step_size 必须放最后",{n:l+1});if(a.completion_step_size<s)return p("第 {{n}} 档:同 step_size 下 completion_step_size 必须升序",{n:l+1})}else s=-1/0;t=a.step_size,s=a.completion_step_size}}return e.some(e=>(e.prompt_step_cost||0)>0||(e.completion_step_cost||0)>0)?null:p("至少有一档的 Prompt 或 Completion 单价 > 0")})(u);e?r(e):(m?.(u),a?.())},children:p("保存到成本表")})]})]}),children:[t.jsx($,{type:"info",closeIcon:null,description:p("档位按 (输入 token, 输出 token) 二维匹配,规则与系统设置→倍率设置→模型阶梯计费一致。step_size = -1 表示无限制(兜底档);单价单位 USD / 1M tokens;缓读/缓写/图像 单价为 0 时回退到 Prompt 单价计算,音频单价为 0 时不计入成本。"),style:{marginBottom:12}}),0===u.length?t.jsx(E,{title:p("尚无档位"),description:p("点击「新增档」或「一键导入」开始配置")}):t.jsx("div",{style:{overflowX:"auto"},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"var(--semi-color-fill-0)"},children:[t.jsx("th",{style:Ae,children:"#"}),t.jsx("th",{style:Ae,children:t.jsx(S,{content:p("输入 token 上限,-1 表示无限制(兜底档)"),children:t.jsx("span",{children:"step_size"})})}),t.jsx("th",{style:Ae,children:t.jsx(S,{content:p("同 step_size 下输出 token 上限,-1 表示无限制"),children:t.jsx("span",{children:"completion_step_size"})})}),ze.map(e=>t.jsx("th",{style:Ae,children:t.jsx(S,{content:p(e.tip),children:t.jsx("span",{children:p(e.label)})})},e.key)),t.jsx("th",{style:{...Ae,width:40}})]})}),t.jsx("tbody",{children:u.map((e,s)=>t.jsxs("tr",{children:[t.jsx("td",{style:Ee,children:t.jsx(Se,{type:"tertiary",children:s+1})}),t.jsx("td",{style:Ee,children:t.jsx(I,{size:"small",step:1,precision:0,value:e.step_size,onChange:e=>_(s,{step_size:Number(e)}),style:{width:110}})}),t.jsx("td",{style:Ee,children:t.jsx(I,{size:"small",step:1,precision:0,value:e.completion_step_size,onChange:e=>_(s,{completion_step_size:Number(e)}),style:{width:130}})}),ze.map(l=>t.jsx("td",{style:Ee,children:t.jsx(I,{size:"small",min:0,step:1e-4,precision:4,innerButtons:!0,value:e[l.key]||0,onChange:e=>_(s,{[l.key]:Number(e)||0}),style:{width:110}})},l.key)),t.jsx("td",{style:Ee,children:t.jsx(T,{icon:t.jsx(ae,{size:12}),size:"small",type:"danger",theme:"borderless",onClick:()=>(e=>{x(t=>t.filter((t,s)=>s!==e))})(s)})})]},s))})]})})]})},Ae={padding:"6px 8px",textAlign:"left",borderBottom:"1px solid var(--semi-color-border)",fontWeight:600,whiteSpace:"nowrap"},Ee={padding:"6px 8px",borderBottom:"1px solid var(--semi-color-border)",verticalAlign:"middle"},Re=({channelId:s,models:c,isEdit:d,visible:h,onClose:m})=>{const{t:p}=l(),u=a(),[x,g]=e.useState([]),[y,_]=e.useState(!1),[f,j]=e.useState(!1),[v,b]=e.useState(!1),[w,B]=e.useState(!1),[$,M]=e.useState(null),[L,J]=e.useState(!1),[P,W]=e.useState(null),D=e.useCallback(async()=>{if(d&&s){_(!0);try{const e=await i.get(`/api/channel/${s}/model-costs`);e?.data?.success?g(function(e,t){const s=new Map;for(const l of e||[])s.set(l.model_name,{model_name:l.model_name,billing_type:l.billing_type||"token",cost_config:l.cost_config||{},dirty:!1});for(const l of t||[])s.has(l)||s.set(l,Te(l));return Array.from(s.values()).sort((e,t)=>e.model_name.localeCompare(t.model_name))}(e.data.data,c)):r(e?.data?.message||p("加载成本配置失败"))}catch(e){r(e?.message||p("加载成本配置失败"))}_(!1)}},[s,d,c,p]);e.useEffect(()=>{h&&d&&s&&D()},[h,d,s,c?.length]);const F=(e,t)=>{g(s=>s.map(s=>s.model_name===e?{...s,...t,cost_config:t.cost_config?{...s.cost_config,...t.cost_config}:s.cost_config,dirty:!0}:s))},V=e=>{const t=e.cost_config||{};return"free"===e.billing_type||("token"===e.billing_type?(t.input||0)>0||(t.output||0)>0||(t.cache_creation||0)>0||(t.cache_read||0)>0||(t.audio_input||0)>0||(t.audio_output||0)>0:"video_size"===e.billing_type?(t.input||0)>0||(t.output||0)>0:"step"===e.billing_type?(t.steps||[]).length>0:(t.unit_cost||0)>0)},K=x.some(e=>e.dirty),q=async(e,l)=>{if(d&&s){B(!0);try{const a={mode:e};"ratio"===e&&(a.ratio=l);const n=await i.post(`/api/channel/${s}/model-costs/suggest-batch`,a);if(n?.data?.success){const s=n.data.data||{},l="ratio"===e&&!L,{filled:a,skippedExisting:i}=((e,t)=>{const s=new Map(x.map(e=>[e.model_name,e])),l=new Map;let a=0;for(const i of e||[]){const e=s.get(i.model_name);e&&(t&&V(e)?a++:l.set(i.model_name,i))}return l.size>0&&g(e=>e.map(e=>{const t=l.get(e.model_name);return t?{...e,billing_type:t.billing_type||e.billing_type,cost_config:t.cost_config||{},dirty:!0}:e})),{filled:l.size,skippedExisting:a}})(s.items,l),r=s.mismatched||[],c=s.skipped||[];o(p("已回填 {{count}} 个模型成本(未保存,请核对后保存)",{count:a})),(r.length>0||i>0||c.length>0)&&N.info({title:p("自动配置结果"),content:t.jsxs("div",{style:{fontSize:13,lineHeight:1.6},children:[t.jsx("div",{children:p("已回填 {{count}} 个模型,请核对后点「保存全部成本配置」。",{count:a})}),i>0&&t.jsx("div",{style:{marginTop:6},children:t.jsx(Se,{type:"tertiary",children:p("跳过 {{count}} 个已配置(未覆盖)。如需重填可勾选「覆盖已配置」。",{count:i})})}),r.length>0&&t.jsxs("div",{style:{marginTop:10},children:[t.jsx(Se,{strong:!0,type:"warning",children:p("上游价与我方倍率对不齐(已按上游回填,请重点核对):")}),t.jsx("div",{style:{maxHeight:160,overflow:"auto",marginTop:4},children:r.map(e=>t.jsxs("div",{children:[e.model_name,"(",p("我方")," ",e.our_ratio," / ",p("上游")," ",e.upstream_ratio,")"]},e.model_name))})]}),c.length>0&&t.jsxs("div",{style:{marginTop:10},children:[t.jsx(Se,{strong:!0,type:"tertiary",children:p("ratio"===e?"以下模型我方无定价,未填充(请手动配置):":"未自动配置(请用「按倍率填充」或手动):")}),t.jsx("div",{style:{maxHeight:160,overflow:"auto",marginTop:4},children:c.join("、")})]})]})})}else r(n?.data?.message||p("自动配置失败"))}catch(a){r(a?.message||p("自动配置失败"))}B(!1)}else r(p("请先保存渠道基础信息再配置成本"))},U=(e,t)=>{if("free"===e)return{field:null,disabled:!0};if("token"===e){const e={input:"input",output:"output",cache_w:"cache_creation",cache_r:"cache_read",audio_in:"audio_input",audio_out:"audio_output"};return{field:e[t],disabled:!e[t]}}return"video_size"===e?"input"===t?{field:"input",disabled:!1}:"output"===t?{field:"output",disabled:!1}:{field:null,disabled:!0}:"input"===t?{field:"unit_cost",disabled:!1}:{field:null,disabled:!0}},H=e.useMemo(()=>[{title:p("模型"),dataIndex:"model_name",width:220,render:(e,s)=>{const l=!c?.includes(e),a=V(s);return t.jsxs("div",{style:{lineHeight:"20px"},children:[t.jsx(Se,{strong:!0,ellipsis:{showTooltip:!0},style:{maxWidth:180,display:"inline-block",fontSize:13},children:e}),!a&&t.jsx(k,{color:"red",size:"small",style:{marginLeft:4},children:p("未配")}),l&&t.jsx(S,{content:p("该模型不在渠道当前模型列表,但有历史成本配置"),children:t.jsx(k,{color:"orange",size:"small",style:{marginLeft:4},children:p("孤儿")})}),s.dirty&&!a&&t.jsx(k,{color:"blue",size:"small",style:{marginLeft:4},children:p("改")})]})}},{title:p("类型"),dataIndex:"billing_type",width:105,render:(e,s)=>t.jsx(C,{value:e,size:"small",optionList:Ce.map(e=>({value:e.value,label:p(e.label)})),onChange:e=>F(s.model_name,{billing_type:e}),style:{width:"100%"}})},{title:t.jsx(S,{content:p("token / 按视频尺寸: input 单价;按次/按秒/按像素: unit_cost;阶梯: 点击进入档位编辑"),children:t.jsx("span",{children:p("Input / 单价")})}),dataIndex:"_input",width:130,render:(e,s)=>{if("step"===s.billing_type)return(e=>{const s=(e.cost_config?.steps||[]).length;return t.jsx(S,{content:p("点击编辑阶梯档位"),children:t.jsx(k,{color:"orange",size:"small",onClick:()=>W({modelName:e.model_name,steps:e.cost_config?.steps||[]}),style:{cursor:"pointer"},children:p("阶梯 ×{{n}}",{n:s})})})})(s);if("free"===s.billing_type)return t.jsx(S,{content:p("成本恒为 0,仅统计用量(毛利=用户付)"),children:t.jsx(k,{color:"green",size:"small",children:p("免费")})});const l=U(s.billing_type,"input");return t.jsx(Ie,{value:s.cost_config?.[l.field]||0,onChange:e=>F(s.model_name,{cost_config:{[l.field]:e}}),disabled:l.disabled})}},{title:p("Output"),dataIndex:"_output",width:130,render:(e,s)=>{const l=U(s.billing_type,"output");return l.disabled||"step"===s.billing_type?t.jsx(Se,{type:"quaternary",children:"—"}):t.jsx(Ie,{value:s.cost_config?.[l.field]||0,onChange:e=>F(s.model_name,{cost_config:{[l.field]:e}}),disabled:l.disabled})}},{title:t.jsx(S,{content:"cache_creation (cache write)",children:t.jsx("span",{children:p("缓写")})}
1),dataIndex:"_cache_w",width:120,render:(e,s)=>{const l=U(s.billing_type,"cache_w");return l.disabled||"step"===s.billing_type?t.jsx(Se,{type:"quaternary",children:"—"}):t.jsx(Ie,{value:s.cost_config?.[l.field]||0,onChange:e=>F(s.model_name,{cost_config:{[l.field]:e}}),disabled:l.disabled})}},{title:t.jsx(S,{content:"cache_read",children:t.jsx("span",{children:p("缓读")})}),dataIndex:"_cache_r",width:120,render:(e,s)=>{const l=U(s.billing_type,"cache_r");return l.disabled||"step"===s.billing_type?t.jsx(Se,{type:"quaternary",children:"—"}):t.jsx(Ie,{value:s.cost_config?.[l.field]||0,onChange:e=>F(s.model_name,{cost_config:{[l.field]:e}}),disabled:l.disabled})}},{title:t.jsx(S,{content:p("音频输入价格(USD/1M tokens,与售价端 AudioRatio 同义;未填则音频成本计 0)"),children:t.jsx("span",{children:p("音频输入")})}),dataIndex:"_audio_in",width:120,render:(e,s)=>{const l=U(s.billing_type,"audio_in");return l.disabled||"step"===s.billing_type?t.jsx(Se,{type:"quaternary",children:"—"}):t.jsx(Ie,{value:s.cost_config?.[l.field]||0,onChange:e=>F(s.model_name,{cost_config:{[l.field]:e}}),disabled:l.disabled})}},{title:t.jsx(S,{content:p("音频补全价格(USD/1M tokens,与售价端 AudioCompletionRatio 同义;未填则音频补全成本按 output 单价计)"),children:t.jsx("span",{children:p("音频补全")})}),dataIndex:"_audio_out",width:120,render:(e,s)=>{const l=U(s.billing_type,"audio_out");return l.disabled||"step"===s.billing_type?t.jsx(Se,{type:"quaternary",children:"—"}):t.jsx(Ie,{value:s.cost_config?.[l.field]||0,onChange:e=>F(s.model_name,{cost_config:{[l.field]:e}}),disabled:l.disabled})}},{title:p("单位"),dataIndex:"_unit",width:80,render:(e,s)=>t.jsx(k,{color:"grey",size:"small",children:Ne[s.billing_type]||"—"})}],[c,p]),G=x.filter(e=>!V(e)).length,Y=K&&G>0;return t.jsxs(N,{visible:h,onCancel:()=>{K?N.confirm({title:p("有未保存的修改"),content:p("关闭后修改将丢失,是否继续?"),onOk:m}):m?.()},title:t.jsxs("span",{children:[p("模型成本配置"),G>0&&t.jsx(k,{color:"red",size:"small",style:{marginLeft:8},children:p("{{count}} 个未配",{count:G})})]}),width:u?"100%":960,fullScreen:u,closeOnEsc:!K,bodyStyle:{padding:u?"8px 12px":"12px 20px",overflow:u?"auto":void 0},footer:t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",flexWrap:"wrap",gap:8},children:[t.jsxs(z,{wrap:!0,children:[t.jsx(O,{checked:v,onChange:e=>b(e.target.checked),children:p("原地修正(不留历史版本)")}),Y&&t.jsx(k,{color:"red",size:"small",children:p("有 {{count}} 个模型未配置成本",{count:G})})]}),t.jsx(T,{icon:t.jsx(le,{size:16}),type:"primary",theme:"solid",onClick:async()=>{if(!d||!s)return void r(p("请先保存渠道基础信息再配置成本"));const e=x.filter(e=>V(e)).map(e=>({model_name:e.model_name,billing_type:e.billing_type,cost_config:e.cost_config}));if(0!==e.length){j(!0);try{const t=await i.post(`/api/channel/${s}/model-costs`,{items:e,correct_in_place:v});t?.data?.success?(o(p("已保存 {{count}} 条成本配置",{count:t.data.data?.saved??e.length})),D()):r(t?.data?.message||p("保存成本配置失败"))}catch(t){r(t?.message||p("保存成本配置失败"))}j(!1)}else n(p("没有可保存的成本配置"))},loading:f,children:p("保存全部成本配置")})]}),children:[t.jsx(Se,{type:"tertiary",style:{fontSize:12,display:"block",marginBottom:6},children:p('为每个模型录入"我们的真实拿货价";不参与用户扣费,仅记录到 cost_logs 用于后台对账')}),t.jsxs("div",{style:{display:"flex",alignItems:"center",marginBottom:8,flexWrap:"wrap",gap:8},children:[t.jsxs(z,{wrap:!0,children:[t.jsx(S,{content:p("成本 = (上游对不齐时取上游,否则我方) 倍率 × 2 × 排序价格(充值汇率×分组倍率);缓存/输出按我方倍率关系自动推算。仅 token / 阶梯生效。"),children:t.jsx(T,{size:"small",type:"primary",theme:"solid",onClick:()=>{N.confirm({title:p("一键自动配成本"),content:p("仅对 token / 阶梯 模型按公式回填成本价(成本 = 上游对不齐时取上游否则我方 倍率 × 2 × 排序价格,缓存/输出按我方倍率自动推算)。其余模型请用「按倍率填充」或手动配置。回填结果可手动修改后再保存。"),onOk:()=>q("auto")})},loading:w,disabled:!d,children:p("一键自动配成本")})}),t.jsx(S,{content:p("成本价 = 我们的价格 × 此倍率(例:0.7 = 我们的价格的 7 折)。默认只填未配置的模型,不覆盖已配;勾选「覆盖已配置」可全表重填。"),children:t.jsx(I,{size:"small",min:0,step:.1,precision:4,placeholder:p("成本倍率"),value:$,onChange:M,disabled:!d,style:{width:120}})}),t.jsx(T,{size:"small",onClick:()=>{$>0?q("ratio",$):n(p("请先填写成本倍率(需大于 0)"))},loading:w,disabled:!d,children:p("按倍率填充")}),t.jsx(S,{content:p("默认只填未配置(空白)的模型,不覆盖一键自动配/已保存/手填的值;勾选后按倍率重填全部模型。"),children:t.jsx(O,{checked:L,onChange:e=>J(e.target.checked),disabled:!d,children:p("覆盖已配置")})})]}),t.jsx("div",{style:{flex:1}}),t.jsx(T,{icon:t.jsx(se,{size:12}),size:"small",type:"tertiary",onClick:D,loading:y,children:p("刷新")})]}),t.jsx(A,{spinning:y,children:u?x.length>0?t.jsx("div",{children:x.map(e=>{const s=e.cost_config||{},l=V(e),a=!c?.includes(e.model_name),i="token"===e.billing_type,r="video_size"===e.billing_type,n="step"===e.billing_type,o={min:0,step:1e-4,precision:4,size:"small",innerButtons:!0,style:{width:"100%"}};return t.jsxs("div",{style:{border:"1px solid var(--semi-color-border)",borderRadius:8,padding:12,marginBottom:8,background:e.dirty?"var(--semi-color-primary-light-default)":void 0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",flexWrap:"wrap",gap:4,marginBottom:8},children:[t.jsx(Se,{strong:!0,style:{fontSize:13,wordBreak:"break-all"},children:e.model_name}),!l&&t.jsx(k,{color:"red",size:"small",children:p("未配")}),a&&t.jsx(k,{color:"orange",size:"small",children:p("孤儿")}),e.dirty&&!l&&t.jsx(k,{color:"blue",size:"small",children:p("改")})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:8},children:[t.jsx(Se,{type:"tertiary",style:{fontSize:12,flexShrink:0},children:p("类型")}),t.jsx(C,{value:e.billing_type,size:"small",optionList:Ce.map(e=>({value:e.value,label:p(e.label)})),onChange:t=>F(e.model_name,{billing_type:t}),style:{flex:1}}),t.jsx(k,{color:"grey",size:"small",children:Ne[e.billing_type]||"—"})]}),n?t.jsx(T,{size:"small",type:"tertiary",onClick:()=>W({modelName:e.model_name,steps:s.steps||[]}),style:{width:"100%"},children:p("编辑阶梯(×{{n}})",{n:(s.steps||[]).length})}):i?t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[t.jsxs("div",{children:[t.jsx(Se,{type:"tertiary",style:{fontSize:11},children:"Input"}),t.jsx(I,{...o,value:s.input||0,onChange:t=>F(e.model_name,{cost_config:{input:Number(t)||0}})})]}),t.jsxs("div",{children:[t.jsx(Se,{type:"tertiary",style:{fontSize:11},children:"Output"}),t.jsx(I,{...o,value:s.output||0,onChange:t=>F(e.model_name,{cost_config:{output:Number(t)||0}})})]}),t.jsxs("div",{children:[t.jsx(Se,{type:"tertiary",style:{fontSize:11},children:p("缓写")}),t.jsx(I,{...o,value:s.cache_creation||0,onChange:t=>F(e.model_name,{cost_config:{cache_creation:Number(t)||0}})})]}),t.jsxs("div",{children:[t.jsx(Se,{type:"tertiary",style:{fontSize:11},children:p("缓读")}),t.jsx(I,{...o,value:s.cache_read||0,onChange:t=>F(e.model_name,{cost_config:{cache_read:Number(t)||0}})})]}),t.jsxs("div",{children:[t.jsx(Se,{type:"tertiary",style:{fontSize:11},children:p("音频输入")}),t.jsx(I,{...o,value:s.audio_input||0,onChange:t=>F(e.model_name,{cost_config:{audio_input:Number(t)||0}})})]}),t.jsxs("div",{children:[t.jsx(Se,{type:"tertiary",style:{fontSize:11},children:p("音频补全")}),t.jsx(I,{...o,value:s.audio_output||0,onChange:t=>F(e.model_name,{cost_config:{audio_output:Number(t)||0}})})]})]}):r?t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[t.jsxs("div",{children:[t.jsx(Se,{type:"tertiary",style:{fontSize:11},children:"Input"}),t.jsx(I,{...o,value:s.input||0,onChange:t=>F(e.model_name,{cost_config:{input:Number(t)||0}})})]}),t.jsxs("div",{children:[t.jsx(Se,{type:"tertiary",style:{fontSize:11},children:"Output"}),t.jsx(I,{...o,value:s.output||0,onChange:t=>F(e.model_name,{cost_config:{output:Number(t)||0}})})]})]}):t.jsxs("div",{children:[t.jsx(Se,{type:"tertiary",style:{fontSize:11},children:p("单价")}),t.jsx(I,{...o,value:s.unit_cost||0,onChange:t=>F(e.model_name,{cost_config:{unit_cost:Number(t)||0}})})]})]},e.model_name)})}):t.jsx(E,{title:p("暂无可配置模型"),description:p('请先在上方"模型"区添加模型')}):t.jsx(R,{columns:H,dataSource:x,rowKey:"model_name",pagination:{pageSize:100,showSizeChanger:!0,pageSizeOpts:[50,100,200]},size:"small",bordered:!0,empty:t.jsx(E,{title:p("暂无可配置模型"),description:p('请先在上方"模型"区添加模型')})})}),t.jsx(Oe,{visible:!!P,onClose:()=>W(null),channelId:s,modelName:P?.modelName,steps:P?.steps||[],onSave:e=>{P?.modelName&&F(P.modelName,{cost_config:{steps:e}})}})]})};Re.checkCostConfigured=async e=>{try{const t=await i.get(`/api/channel/${e}/model-costs`);if(!t?.data?.success)return{configured:!0,total:0,missing:0};const s=t.data.data||[],l=s.length,a=s.filter(e=>{const t=e.cost_config||{};return"token"===e.billing_type?(t.input||0)<=0&&(t.output||0)<=0&&(t.cache_creation||0)<=0&&(t.cache_read||0)<=0&&(t.audio_input||0)<=0&&(t.audio_output||0)<=0:"video_size"===e.billing_type?(t.input||0)<=0&&(t.output||0)<=0:"step"===e.billing_type?
10===(t.steps||[]).length:(t.unit_cost||0)<=0}).length;return{configured:0===a&&l>0,total:l,missing:a}}catch{return{configured:!0,total:0,missing:0}}};const{Text:Be,Title:$e}=w,Me={"gpt-3.5-turbo":"gpt-3.5-turbo-0125"},Le={"gpt-4o":"gpt-4o-2024-08-06","gpt-3.5-turbo":"gpt-3.5-turbo-0125","gpt-4o-mini":"gpt-4o-mini-2024-07-18","o1-mini":"o1-mini-2024-09-12","o1-preview":"o1-preview-2024-09-12","gpt-4-turbo":"gpt-4-turbo-2024-04-09"},Je={400:"500"},Pe={default:"us-central1","claude-3-5-sonnet-20240620":"europe-west1"},We={"gpt-4o-2024-11-20":60},De={prompt_filter_results:!0,"choices.0.content_filter_results":!0},Fe={ChannelRequestRateLimitEnabled:!0,ChannelRequestRateLimitDurationMinutes:1,ChannelRequestRateLimitCount:1e3,ChannelRequestRateLimitSuccessCount:1e3,ChannelRequestRateLimitFailureCount:1e3};function Ve(e){switch(e){case 15:return"按照如下格式输入:APIKey|SecretKey";case 18:return"按照如下格式输入:APPID|APISecret|APIKey";case 22:return"按照如下格式输入:APIKey-AppId,例如:fastgpt-0sp2gtvfdgyi4k30jwlgwf1i-64f335d84283f05518e9e041";case 23:return"按照如下格式输入:AppId|SecretId|SecretKey";case 33:return"按照如下格式输入:Ak|Sk|Region";case 50:case 101:return"按照如下格式输入: AccessKey|SecretKey(官方API)或 sk-xxxxx(第三方代理)";case 111:return"按照如下格式输入:Token|Region";case 51:return"按照如下格式输入: Access Key ID|Secret Access Key";case 110:return"按照如下格式输入: SubAppId|SecretId|SecretKey(官方API)或 sk-xxxxx(第三方代理)";default:return"请输入渠道对应的鉴权密钥"}}const Ke={touchAction:"pan-y",WebkitUserSelect:"none",userSelect:"none"},qe="edit-channel-select-dropdown",Ue={maxWidth:"calc(100vw - 32px)",boxSizing:"border-box"},He=x=>{const{t:g}=l();s();const y=x.editingChannel.id,_=void 0!==y,[f,j]=e.useState(!1),[b,w]=e.useState(!1),S=a(),[C,I]=e.useState(),E=e.useRef(null),R=e.useMemo(()=>{if(S)return{...Ue,...C?{width:C,minWidth:C}:{}}},[C,S]),V=e=>{S&&(E.current&&cancelAnimationFrame(E.current),e&&(E.current=requestAnimationFrame(()=>{const e=document.querySelector(".semi-select-open"),t=Math.floor(e?.getBoundingClientRect().width||0);t>0&&I(e=>e===t?e:t),E.current=null})))},K=()=>{x.handleClose()},q={name:"",type:1,key:"",openai_organization:"",max_input_tokens:0,base_url:"",other:"",model_mapping:"",return_model_mapping:"",model_timeout_mapping:"",status_code_mapping:"",models:[],auto_ban:!0,failure_timeout_ban_limit:50,test_model:"",test_prompt:"",test_path:"",groups:["default"],priority:0,weight:0,tag:"",price:1,recharge_price:1,group_ratio:1,setting:"",param_override:"",header_override:"",multi_key_mode:"random",force_format:!1,thinking_to_content:!1,proxy:"",pass_through_body_enabled:!1,system_prompt:"",system_prompt_override:!1,filter_fields:"",retry_on_content_filter:!1,channel_rate_limit:"",trust_upstream_token:!0,claude_beta_filters:"",bedrock_compat:!1,vertex_key_type:"json",allow_service_tier:!1,disable_store:!1,settings:""},[U,H]=e.useState(!1),[G,Y]=e.useState(!1),[Z,X]=e.useState("random"),[Q,ee]=e.useState(!0),[te,se]=e.useState(q),[ae,ie]=e.useState([]),[re,ue]=e.useState([]),[xe,ge]=e.useState([]),[ye,_e]=e.useState([]),[fe,je]=e.useState([]),[ve,be]=e.useState(""),[we,ke]=e.useState(""),[Se,Ce]=e.useState(!1),Ne=e.useRef(null),[ze,Te]=e.useState([]),[Ie,Oe]=e.useState([]),Ae=e.useRef(new Set),[Ee,He]=e.useState(!1),[Ge,Ye]=e.useState(""),[Ze,Xe]=e.useState(!1),Qe=e.useRef(0),et=e.useRef(x.visible),tt=e.useRef(y);et.current=x.visible,tt.current=y;const st=()=>({...q}),lt=e=>{se(e),Ne.current?.setValues(e)},at=()=>
1{Xe(!1),Te([]),Oe([]),Ae.current.clear(),He(!1),H(!1),Y(!1),X("random")};e.useEffect(()=>()=>{E.current&&cancelAnimationFrame(E.current)},[]);const it=(e,t)=>{Ne.current&&Ne.current.setValue(e,t),se(s=>({...s,[e]:t}))},rt=(e,t)=>{Ne.current&&Ne.current.setValue(e,t),se(s=>({...s,[e]:t}));let s={};if(te.settings)try{s=JSON.parse(te.settings)}catch(a){console.error("解析设置失败:",a)}s[e]=t;const l=JSON.stringify(s);ot("settings",l)},nt=e=>{Ne.current&&(Ne.current.setValue("type",e),Ne.current.setValue("other","")),se(t=>({...t,type:e,other:""}));let t=[];switch(e){case 2:t=["mj_imagine","mj_variation","mj_reroll","mj_blend","mj_upscale","mj_describe","mj_uploads"];break;case 5:t=["swap_face","mj_imagine","mj_video","mj_edits","mj_variation","mj_reroll","mj_blend","mj_upscale","mj_describe","mj_zoom","mj_shorten","mj_modal","mj_inpaint","mj_custom_zoom","mj_high_variation","mj_low_variation","mj_pan","mj_uploads"];break;case 36:t=["suno_music","suno_music_open","suno_lyrics"];break;default:t=h(e)}0===te.models.length&&(Ne.current?.setValue("models",t),se(e=>({...e,models:t}))),_e(t),Xe(!1)},ot=(e,t)=>{if("type"===e){const e=void 0!==te.other&&null!==te.other&&""!==String(te.other).trim();return t!==te.type&&e?void N.confirm({title:g("警告"),content:g("切换渠道类型会清空当前已填写的额外参数(部署地区/模型版本/知识库ID/Account ID 等,不同类型下含义不同),是否继续?"),onOk:()=>nt(t),onCancel:()=>{Ne.current&&Ne.current.setValue("type",te.type)}}):void nt(t)}Ne.current&&Ne.current.setValue(e,t),"models"===e&&Array.isArray(t)&&(t=Array.from(new Set(t.map(e=>(e||"").trim())))),"base_url"===e&&t.endsWith("/v1")?N.confirm({title:g("警告"),content:"不需要在末尾加/v1,New API会自动处理,添加后可能导致请求失败,是否继续?",onOk:()=>{se(s=>({...s,[e]:t}))}}):se(s=>({...s,[e]:t}))};e.useEffect(()=>{const e=new Map;ae.forEach(t=>{const s=(t.value||"").trim();e.has(s)||e.set(s,t)}),te.models.forEach(t=>{const s=(t||"").trim();e.has(s)||e.set(s,{key:s,label:s,value:s})});const s=c(g),l=Array.from(e.values()).map(e=>{const l=e.value;let a=null;for(const[t,i]of Object.entries(s))if("all"!==t&&i.filter({model_name:l})){a=i.icon;break}return{...e,label:t.jsxs("span",{className:"flex items-center gap-1",children:[a,l]})}});ue(l)},[ae,te.models,g]),e.useEffect(()=>{(async()=>{try{let e=await i.get("/api/channel/models");const t=e.data.data.map(e=>{const t=(e.id||"").trim();return{key:t,label:t,value:t}});ie(t),je(e.data.data.map(e=>e.id)),_e(e.data.data.filter(e=>e.id.startsWith("gpt-")||e.id.startsWith("text-")).map(e=>e.id))}catch(e){r(e.message)}})().then(),(async()=>{try{let e=await i.get("/api/group/");if(void 0===e)return;const t=e.data.data;if(t&&t.groups){const{groups:e,ratios:s={},descriptions:l={}}=t;ge(e.map(e=>({label:e,value:e,ratio:s[e]||1,description:l[e]||""})))}else Array.isArray(t)&&ge(t.map(e=>({label:e,value:e,ratio:1,description:""})))}catch(e){r(e.message)}})().then()},[]),e.useEffect(()=>{x.visible?_?(at(),ee(q.auto_ban),j(!0),lt(st()),(async()=>{const e=++Qe.current,t=y;j(!0);try{let l=await i.get(`/api/channel/${t}`);if(e!==Qe.current||!et.current||tt.current!==t)return;if(void 0===l)return;const{success:a,message:n,data:o}=l.data;if(a){if(""===o.models?o.models=[]:o.models=o.models.split(","),""===o.group?o.groups=[]:o.groups=o.group.split(","),""!==o.model_mapping&&(o.model_mapping=JSON.stringify(JSON.parse(o.model_mapping),null,2)),""!==o.return_model_mapping&&(o.return_model_mapping=JSON.stringify(JSON.parse(o.return_model_mapping),null,2)),""!==o.model_timeout_mapping&&(o.model_timeout_mapping=JSON.stringify(JSON.parse(o.model_timeout_mapping),null,2)),o.param_override&&""!==o.param_override)try{o.param_override=JSON.stringify(JSON.parse(o.param_override),null,2)}catch(s){console.error("解析参数覆盖失败:",s),o.param_override=""}if(o.header_override&&""!==o.header_override)try{o.header_override=JSON.stringify(JSON.parse(o.header_override),null,2)}catch(s){console.error("解析请求头覆盖失败:",s),o.header_override=""}if(""!==o.setting)try{const e=JSON.parse(o.setting);o.force_format=e.force_format||!1,o.thinking_to_content=e.thinking_to_content||!1,o.proxy=e.proxy||"",o.pass_through_body_enabled=e.pass_through_body_enabled||!1,o.system_prompt=e.system_prompt||"",o.system_prompt_override=e.system_prompt_override||!1,o.filter_fields=e.filter_fields?JSON.stringify(e.filter_fields,null,2):"",o.retry_on_content_filter=e.retry_on_content_filter||!1,o.channel_rate_limit=e.channel_rate_limit?JSON.stringify(e.channel_rate_limit,null,2):"",o.trust_upstream_token=!1!==e.trust_upstream_token,o.claude_beta_filters=e.claude_beta_filters?e.claude_beta_filters.join(","):"",o.bedrock_compat=e.bedrock_compat||!1,o.test_prompt=e.test_prompt||"",o.test_path=e.test_path||""}catch(s){console.error("解析渠道额外设置失败:",s),o.force_format=!1,o.thinking_to_content=!1,o.proxy="",o.pass_through_body_enabled=!1}if(o.settings)try{const e=JSON.parse(o.settings);o.vertex_key_type=e.vertex_key_type||"json",o.allow_service_tier=e.allow_service_tier||!1,o.disable_store=e.disable_store||!1}catch(s){console.error("解析其他设置失败:",s),o.vertex_key_type="json",o.allow_service_tier=!1,o.disable_store=!1}else o.vertex_key_type="json",o.allow_service_tier=!1,o.disable_store=!1;const e=o.channel_info||{},t=!0===e.is_multi_key;if(He(t),t){H(!0),Y(!0);const t=e.multi_key_mode||"random";X(t),o.multi_key_mode=t}else H(!1),Y(!1);const l={...o,auto_ban:0!==o.auto_ban};lt(l),ee(l.auto_ban),_e(h(l.type))}else r(n)}catch(s){if(e!==Qe.current||!et.current||tt.current!==t)return;console.error("加载渠道详情失败:",s),s?.isAxiosError||r(g("加载渠道详情失败"))}finally{e===Qe.current&&j(!1)}})()):(()=>{at();const e=st(),t=h(e.type);e.models=t,_e(t),ee(e.auto_ban),lt(e),j(!1)})():(at(),ee(q.auto_ban),_e(h(q.type)),j(!1),se(st()),Ne.current?.reset())},[x.visible,_,y]),e.useEffect(()=>{x.visible&&Ne.current&&void 0!==te.other&&te.other!==Ne.current.getValue("other")&&Ne.current.setValue("other",te.other)},[te.type,te.other,x.visible]),e.useEffect(()=>{if(!x.visible)return;const e=[document.body,document.getElementById("app-outer-layout"),document.getElementById("main-content")].filter(
1Boolean).map(e=>({element:e,overflow:e.style.overflow,overflowY:e.style.overflowY,overscrollBehavior:e.style.overscrollBehavior}));e.forEach(({element:e})=>{e.style.overflow="hidden",e.style.overflowY="hidden",e.style.overscrollBehavior="none"});const t=e=>{const t=e.target;t instanceof Element&&(t.closest(".semi-sidesheet-mask:not(.semi-sidesheet-mask-hidden)")||t.closest(`.${qe}`)&&!t.closest(".semi-select-option-list"))&&e.preventDefault()},s=e=>{const t=e.target;if(!(t instanceof Element))return;const s=document.querySelector(`.${qe}`),l=document.querySelector(".semi-select-open");s&&l&&!s.contains(t)&&!l.contains(t)&&t.dispatchEvent(new MouseEvent("mousedown",{bubbles:!0,cancelable:!0,view:window}))};return document.addEventListener("wheel",t,{passive:!1,capture:!0}),document.addEventListener("touchmove",t,{passive:!1,capture:!0}),document.addEventListener("touchstart",s,{passive:!0,capture:!0}),()=>{document.removeEventListener("wheel",t,!0),document.removeEventListener("touchmove",t,!0),document.removeEventListener("touchstart",s,!0),e.forEach(({element:e,overflow:t,overflowY:s,overscrollBehavior:l})=>{e.style.overflow=t,e.style.overflowY=s,e.style.overscrollBehavior=l})}},[x.visible]);const ct=({fileList:e})=>{Ae.current.clear(),(async()=>{let t=[],s=[];const l=[];for(const i of e){const e=i.fileInstance;if(e)try{const l=await e.text();s.push(JSON.parse(l)),t.push(i)}catch(a){Ae.current.has(i.name)||(l.push(i.name),Ae.current.add(i.name))}}!U&&t.length>1&&(t=[t[t.length-1]],s=[s[s.length-1]]),Te(s),Oe(t),Ne.current&&Ne.current.setValue("vertex_files",t),se(e=>({...e,vertex_files:t})),l.length>0&&r(g("以下文件解析失败,已忽略:{{list}}",{list:l.join(", ")}))})()},dt=()=>{if(""===ve.trim())return;const e=ve.split(",").map(e=>e.trim());let t=[...te.models],s=[...re];const l=[];e.forEach(e=>{e&&!t.includes(e)&&(t.push(e),s.push({key:e,label:e,value:e}),l.push(e))}),ue(s),be(""),ot("models",t),l.length>0?o(g("已新增 {{count}} 个模型:{{list}}",{count:l.length,list:l.join(", ")})):n(g("未发现新增模型"))},ht=!_||Ee?t.jsxs(z,{children:[!_&&t.jsx(O,{disabled:_,checked:U,onChange:e=>{const t=e.target.checked;!t&&Ie.length>1?N.confirm({title:g("切换为单密钥模式"),content:g("将仅保留第一个密钥文件,其余文件将被移除,是否继续?"),onOk:()=>{const e=Ie[0],t=ze[0]?[ze[0]]:[];Oe([e]),Te(t),Ne.current?.setValue("vertex_files",[e]),se(t=>({...t,vertex_files:[e]})),H(!1),Y(!1),X("random")},onCancel:()=>{H(!0)},centered:!0}):(H(t),t?(Xe(!1),41===te.type&&(Ne.current&&Ne.current.setValue("key",""),ot("key",""))):(Y(!1),X("random")))},children:g("批量创建")}),U&&t.jsxs(t.Fragment,{children:[t.jsx(O,{disabled:_,checked:G,onChange:()=>{Y(e=>{const t=!e;return Ne.current?.setValue("multi_key_mode",t?Z:void 0),se(e=>{const s={...e};return t?s.multi_key_mode=Z:delete s.multi_key_mode,s}),t})},children:g("密钥聚合模式")}),41!==te.type&&t.jsx(T,{size:"small",type:"tertiary",theme:"outline",onClick:()=>{const e=Ne.current?.getValue("key")||te.key||"";if(!e.trim())return void n(g("请先输入密钥"));const t=e.split("\n"),s=t.length,l=new Set,a=[];t.forEach(e=>{const t=e.trim();t&&!l.has(t)&&(l.add(t),a.push(t))});const i=a.length,r=a.join("\n");Ne.current&&Ne.current.setValue("key",r),ot("key",r);const c=g("去重完成:去重前 {{before}} 个密钥,去重后 {{after}} 个密钥",{before:s,after:i});s===i?n(g("未发现重复密钥")):o(c)},style:{textDecoration:"underline"},children:g("密钥去重")})]})]}):null,mt=e.useMemo(()=>v.map(e=>({...e,label:e.label})),[]),pt=e=>{const{disabled:s,selected:l,label:a,value:i,focused:r,className:n,style:o,onMouseEnter:c,onClick:d,...h}=e,m=Ge?[Ge]:[],p=["flex items-center gap-3 px-3 py-2 transition-all duration-200 rounded-lg mx-2 my-1",r&&"bg-blue-50 shadow-sm",l&&"bg-blue-100 text-blue-700 shadow-lg ring-2 ring-blue-200 ring-opacity-50",s&&"opacity-50 cursor-not-allowed",!s&&"hover:bg-gray-50 hover:shadow-md cursor-pointer",n].filter(Boolean).join(" ");return t.jsx("div",{style:{...o,...Ke},className:p,onClick:()=>!s&&d(),onPointerEnter:e=>{"touch"!==e.pointerType&&c()},children:t.jsxs("div",{className:"flex items-center gap-3 w-full",children:[t.jsx("div",{className:"flex-shrink-0 w-5 h-5 flex items-center justify-center",children:u(i)}),t.jsx("div",{className:"flex-1 min-w-0",children:t.jsx(F,{sourceString:a,searchWords:m,className:"text-sm font-medium truncate"})}),l&&t.jsx("div",{className:"flex-shrink-0 text-blue-600",children:t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"currentColor",children:t.jsx("path",{d:"M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"})})})]})})};return t.jsx(t.Fragment,{children:t.jsxs(B,{placement:_?"right":"left",title:t.jsxs(z,{children:[t.jsx(k,{color:"blue",shape:"circle",children:g(_?"编辑":"新建")}),t.jsx($e,{heading:4,className:"m-0",children:g(_?"更新渠道信息":"创建新的渠道")})]}),bodyStyle:{padding:"0"},maskStyle:{touchAction:"none",overscrollBehavior:"none"},visible:x.visible,width:S?"100%":600,footer:t.jsx("div",{className:"flex justify-end bg-white",children:t.jsxs(z,{children:[t.jsx(T,{theme:"solid",onClick:()=>
1Ne.current?.submitForm(),icon:t.jsx(le,{size:16}),children:g("提交")}),t.jsx(T,{theme:"light",type:"primary",onClick:K,icon:t.jsx(pe,{size:16}),children:g("取消")})]})}),closeIcon:null,onCancel:()=>K(),children:[t.jsx(M,{initValues:q,getFormApi:e=>Ne.current=e,onSubmit:async()=>{let e={...Ne.current?Ne.current.getValues():{}};if(41===e.type)if("api_key"===(e.vertex_key_type||"json")){if(!(_||e.key&&""!==e.key.trim()))return void n(g("请输入密钥")+"!")}else if(Ze){if(e.key&&""!==e.key.trim())try{const t=JSON.parse(e.key);e.key=JSON.stringify(t)}catch(h){return void r(g("密钥格式无效,请输入有效的 JSON 格式密钥"))}else if(!_)return void n(g("请输入密钥")+"!")}else{let t=ze;if(0===t.length&&Ie.length>0)try{t=(await Promise.all(Ie.map(async e=>{const t=e.fileInstance;if(!t)return null;const s=await t.text();return JSON.parse(s)}))).filter(Boolean)}catch(h){return void r(g("解析密钥文件失败: {{msg}}",{msg:h.message}))}if(0===t.length){if(!_)return void n(g("请上传密钥文件")+"!");delete e.key}else e.key=U?JSON.stringify(t):JSON.stringify(t[0])}if(!_||e.key&&""!==e.key.trim()||delete e.key,delete e.vertex_files,!(_||e.name&&e.key))return void n(g("请填写渠道名称和渠道密钥!"));if(!Array.isArray(e.models)||0===e.models.length)return void n(g("请至少选择一个模型")+"!");if(_&&y){const e=await Re.checkCostConfigured(y);e.configured||m(g("提示:还有 {{count}} 个模型未配置成本,对账数据会缺失,建议尽快补全",{count:e.missing||e.total||"部分"}))}if(e.model_mapping&&""!==e.model_mapping&&!p(e.model_mapping))return void n(g("模型映射必须是合法的 JSON 格式!"));if(e.return_model_mapping&&""!==e.return_model_mapping&&!p(e.return_model_mapping))return void n(g("返回模型重定向必须是合法的 JSON 格式!"));if(e.model_timeout_mapping&&""!==e.model_timeout_mapping&&!p(e.model_timeout_mapping))return void n(g("模型超时限制必须是合法的 JSON 格式!"));if(e.param_override&&""!==e.param_override&&!p(e.param_override))return void n(g("参数覆盖必须是合法的 JSON 格式!"));if(e.header_override&&""!==e.header_override&&!p(e.header_override))return void n(g("请求头覆盖必须是合法的 JSON 格式!"));const t={force_format:e.force_format||!1,thinking_to_content:e.thinking_to_content||!1,proxy:e.proxy||"",pass_through_body_enabled:e.pass_through_body_enabled||!1,system_prompt:e.system_prompt||"",system_prompt_override:e.system_prompt_override||!1};if(e.filter_fields&&""!==e.filter_fields.trim())try{t.filter_fields=JSON.parse(e.filter_fields)}catch(u){return void n(g("过滤字段设置必须是合法的 JSON 格式!"))}if(e.retry_on_content_filter&&(t.retry_on_content_filter=!0),e.channel_rate_limit&&""!==e.channel_rate_limit.trim())try{t.channel_rate_limit=JSON.parse(e.channel_rate_limit)}catch(u){return void n(g("渠道限流设置必须是合法的 JSON 格式!"))}let s;!1===e.trust_upstream_token&&(t.trust_upstream_token=!1),e.claude_beta_filters&&""!==e.claude_beta_filters.trim()&&(t.claude_beta_filters=e.claude_beta_filters.split(",").map(e=>e.trim()).filter(e=>e)),e.bedrock_compat&&(t.bedrock_compat=!0),e.test_prompt&&""!==e.test_prompt.trim()&&(t.test_prompt=e.test_prompt.trim()),e.test_path&&""!==e.test_path.trim()&&(t.test_path=e.test_path.trim()),e.setting=JSON.stringify(t),delete e.vertex_key_type,delete e.allow_service_tier,delete e.disable_store,e.base_url&&e.base_url.endsWith("/")&&(e.base_url=e.base_url.slice(0,e.base_url.length-1)),18===e.type&&""===e.other&&(e.other="v2.1"),e.auto_ban=e.auto_ban?1:0,e.failure_timeout_ban_limit=e.failure_timeout_ban_limit||50,e.models=e.models.join(","),e.group=(e.groups||[]).join(",");let l="single";U&&(l=G?"multi_to_single":"batch"),s=_?await i.put("/api/channel/",{...e,id:parseInt(y)}):await i.post("/api/channel/",{mode:l,multi_key_mode:"multi_to_single"===l?Z:void 0,channel:e});const{success:a,message:c,data:d}=s.data;a?(_?d&&d.price_changed?o(g(`价格变动,原渠道 #${d.old_channel_id} 已归档,新渠道 #${d.new_channel_id} 已创建`)):o(g("渠道更新成功!")):o(g("渠道创建成功!")),x.refresh(),x.handleClose()):r(c)},children:()=>t.jsx(A,{spinning:f,children:t.jsxs("div",{className:"p-2",children:[t.jsxs(L,{className:"!rounded-2xl shadow-sm border-0 mb-6",children:[t.jsxs("div",{className:"flex items-center mb-2",children:[t.jsx(J,{size:14,color:"blue",className:"mr-2 shadow-md",children:t.jsx(ne,{size:16})}),t.jsxs("div",{children:[t.jsx(Be,{className:"text-lg font-medium",children:g("基本信息")}),t.jsx("div",{className:"text-xs text-gray-600",children:g("渠道的基本配置信息")})]})]}),t.jsx(M.Select,{field:"type",label:g("类型"),placeholder:g("请选择渠道类型"),rules:[{required:!0,message:g("请选择渠道类型")}],dropdownClassName:qe,dropdownMatchSelectWidth:!0,dropdownStyle:R,autoAdjustOverflow:!0,onDropdownVisibleChange:V,optionList:mt,style:{width:"100%"},filter:!0,searchPosition:"dropdown",onSearch:e=>Ye(e),renderOptionItem:pt,onChange:e=>ot("type",e)}),t.jsx(M.Input,{field:"name",label:g("名称"),placeholder:g("请为渠道命名"),rules:[{required:!0,message:g("请为渠道命名")}],showClear:!0,onChange:e=>ot("name",e),autoComplete:"new-password"}),41===te.type&&t.jsx(M.Select,{field:"vertex_key_type",label:g("密钥格式"),placeholder:g("请选择密钥格式"),dropdownClassName:qe,dropdownMatchSelectWidth:!0,dropdownStyle:R,autoAdjustOverflow:!0,onDropdownVisibleChange:V,optionList:[{label:"JSON",value:"json"},{label:"API Key",value:"api_key"}],style:{width:"100%"},value:te.vertex_key_type||"json",onChange:e=>
1{rt("vertex_key_type",e),"api_key"===e&&(H(!1),Xe(!1),Te([]),Oe([]),Ne.current&&Ne.current.setValue("vertex_files",[]),se(e=>({...e,vertex_files:[]})))},extraText:"api_key"===te.vertex_key_type?g("API Key 模式下不支持批量创建"):g("JSON 模式支持手动输入或上传服务账号 JSON")}),U?41===te.type&&"json"===(te.vertex_key_type||"json")?t.jsx(M.Upload,{field:"vertex_files",label:g("密钥文件 (.json)"),accept:".json",multiple:!0,draggable:!0,dragIcon:t.jsx(oe,{size:16}),dragMainText:g("点击上传文件或拖拽文件到这里"),dragSubText:g("仅支持 JSON 文件,支持多文件"),style:{marginTop:10},uploadTrigger:"custom",beforeUpload:()=>!1,onChange:ct,fileList:Ie,rules:_?[]:[{required:!0,message:g("请上传密钥文件")}],extraText:ht}):t.jsx(M.TextArea,{field:"key",label:g("密钥"),placeholder:g("请输入密钥,一行一个"),rules:_?[]:[{required:!0,message:g("请输入密钥")}],autosize:!0,autoComplete:"new-password",onChange:e=>ot("key",e),extraText:ht,showClear:!0}):t.jsx(t.Fragment,{children:41===te.type&&"json"===(te.vertex_key_type||"json")?t.jsxs(t.Fragment,{children:[!U&&t.jsxs("div",{className:"flex items-center justify-between mb-3",children:[t.jsx(Be,{className:"text-sm font-medium",children:g("密钥输入方式")}),t.jsxs(z,{children:[t.jsx(T,{size:"small",type:Ze?"tertiary":"primary",onClick:()=>{Xe(!1),Ne.current&&Ne.current.setValue("key",""),ot("key","")},children:g("文件上传")}),t.jsx(T,{size:"small",type:Ze?"primary":"tertiary",onClick:()=>
1{Xe(!0),Te([]),Oe([]),Ne.current&&Ne.current.setValue("vertex_files",[]),se(e=>({...e,vertex_files:[]}))},children:g("手动输入")})]})]}),U&&t.jsx($,{type:"info",description:g("批量创建模式下仅支持文件上传,不支持手动输入"),className:"!rounded-lg mb-3"}),Ze&&!U?t.jsx(M.TextArea,{field:"key",label:g(_?"密钥(编辑模式下,保存的密钥不会显示)":"密钥"),placeholder:g("channel_placeholder_005"),rules:_?[]:[{required:!0,message:g("请输入密钥")}],autoComplete:"new-password",onChange:e=>ot("key",e),extraText:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Be,{type:"tertiary",size:"small",children:g("请输入完整的 JSON 格式密钥内容")}),ht]}),autosize:!0,showClear:!0}):t.jsx(M.Upload,{field:"vertex_files",label:g("密钥文件 (.json)"),accept:".json",draggable:!0,dragIcon:t.jsx(oe,{size:16}),dragMainText:g("点击上传文件或拖拽文件到这里"),dragSubText:g("仅支持 JSON 文件"),style:{marginTop:10},uploadTrigger:"custom",beforeUpload:()=>!1,onChange:ct,fileList:Ie,rules:_?[]:[{required:!0,message:g("请上传密钥文件")}],extraText:ht})]}):t.jsx(M.Input,{field:"key",label:g(_?"密钥(编辑模式下,保存的密钥不会显示)":"密钥"),placeholder:g(Ve(te.type)),rules:_?[]:[{required:!0,message:g("请输入密钥")}],autoComplete:"new-password",onChange:e=>ot("key",e),extraText:ht,showClear:!0})}),U&&G&&t.jsxs(t.Fragment,{children:[t.jsx(M.Select,{field:"multi_key_mode",label:g("密钥聚合模式"),placeholder:g("请选择多密钥使用策略"),dropdownClassName:qe,dropdownMatchSelectWidth:!0,dropdownStyle:R,autoAdjustOverflow:!0,onDropdownVisibleChange:V,optionList:[{label:g("随机"),value:"random"},{label:g("轮询"),value:"polling"}],style:{width:"100%"},value:te.multi_key_mode||"random",onChange:e=>{X(e),ot("multi_key_mode",e)}}),"polling"===te.multi_key_mode&&t.jsx($,{type:"warning",description:g("轮询模式必须搭配Redis和内存缓存功能使用,否则性能将大幅降低,并且无法实现轮询功能"),className:"!rounded-lg mt-2"})]}),18===te.type&&t.jsx(M.Input,{field:"other",label:g("模型版本"),placeholder:"请输入星火大模型版本,注意是接口地址中的版本号,例如:v2.1",onChange:e=>ot("other",e),showClear:!0}),41===te.type&&t.jsx(M.TextArea,{field:"other",label:g("部署地区"),placeholder:g("channel_placeholder_006"),autosize:!0,onChange:e=>ot("other",e),rules:[{required:!0,message:g("请填写部署地区")}],extraText:t.jsx(Be,{className:"!text-primary cursor-pointer",onClick:()=>ot("other",JSON.stringify(Pe,null,2)),children:g("填入模板")}),showClear:!0}),21===te.type&&t.jsx(M.Input,{field:"other",label:g("知识库 ID"),placeholder:"请输入知识库 ID,例如:123456",onChange:e=>ot("other",e),showClear:!0}),39===te.type&&t.jsx(M.Input,{field:"other",label:"Account ID",placeholder:"请输入Account ID,例如:d6b5da8hk1awo8nap34ube6gh",onChange:e=>ot("other",e),showClear:!0}),49===te.type&&t.jsx(M.Input,{field:"other",label:g("智能体ID"),placeholder:"请输入智能体ID,例如:7342866812345",onChange:e=>ot("other",e),showClear:!0}),1===te.type&&t.jsx(M.Input,{field:"openai_organization",label:g("组织"),placeholder:g("请输入组织org-xxx"),showClear:!0,helpText:g("组织,不填则为默认组织"),onChange:e=>ot("openai_organization",e)})]}),t.jsxs(L,{className:"!rounded-2xl shadow-sm border-0 mb-6",children:[t.jsxs("div",{className:"flex items-center mb-2",children:[t.jsx(J,{size:14,color:"green",className:"mr-2 shadow-md",children:t.jsx(ce,{size:16})}),t.jsxs("div",{children:[t.jsx(Be,{className:"text-lg font-medium",children:g("API 配置")}),t.jsx("div",{className:"text-xs text-gray-600",children:g("API 地址和相关配置")})]})]}),40===te.type&&t.jsx($,{type:"info",description:t.jsxs("div",{children:[t.jsxs(Be,{strong:!0,children:[g("邀请链接"),":"]}),t.jsx(Be,{link:!0,underline:!0,className:"ml-2 cursor-pointer",onClick:()=>window.open("https://cloud.siliconflow.cn/i/hij0YNTZ"),children:"https://cloud.siliconflow.cn/i/hij0YNTZ"})]}),className:"!rounded-lg"}),3===te.type&&t.jsxs(t.Fragment,{children:[t.jsx($,{type:"warning",description:g('2025年5月10日后添加的渠道,不需要再在部署的时候移除模型名称中的"."'),className:"!rounded-lg"}),t.jsx("div",{children:t.jsx(M.TextArea,{field:"base_url",label:"AZURE_OPENAI_ENDPOINT",placeholder:g("channel_placeholder_004"),onChange:e=>ot("base_url",e),autosize:{minRows:2,maxRows:6},showClear:!0})}),t.jsx("div",{children:t.jsx(M.Input,{field:"other",label:g("默认 API 版本"),placeholder:g("请输入默认 API 版本,例如:2025-04-01-preview"),onChange:e=>ot("other",e),showClear:!0})})]}),8===te.type&&t.jsxs(t.Fragment,{children:[t.jsx($,{type:"warning",description:g("如果你对接的是上游One API或者New API等转发项目,请使用OpenAI类型,不要使用此类型,除非你知道你在做什么。"),className:"!rounded-lg"}),t.jsx("div",{children:t.jsx(M.Input,{field:"base_url",label:g("完整的 Base URL,支持变量{model}"),placeholder:g("请输入完整的URL,例如:https://api.openai.com/v1/c
1hat/completions"),onChange:e=>ot("base_url",e),showClear:!0})})]}),37===te.type&&t.jsx($,{type:"warning",description:g("Dify渠道只适配chatflow和agent,并且agent不支持图片!"),className:"!rounded-lg"}),3!==te.type&&8!==te.type&&22!==te.type&&36!==te.type&&t.jsx("div",{children:t.jsx(M.TextArea,{field:"base_url",label:g("API地址"),placeholder:g("channel_placeholder_003"),onChange:e=>ot("base_url",e),autosize:{minRows:2,maxRows:6},showClear:!0,extraText:g("对于官方渠道,new-api已经内置地址,除非是第三方代理站点或者Azure的特殊接入地址,否则不需要填写。多个地址请每行一个,系统会自动负载均衡。")})}),22===te.type&&t.jsx("div",{children:t.jsx(M.TextArea,{field:"base_url",label:g("私有部署地址"),placeholder:g("请输入私有部署地址,格式为:https://fastgpt.run/api/openapi\n支持多个地址负载均衡,每行一个"),onChange:e=>ot("base_url",e),autosize:{minRows:2,maxRows:6},showClear:!0})}),36===te.type&&t.jsx("div",{children:t.jsx(M.TextArea,{field:"base_url",label:g("注意非Chat API,请务必填写正确的API地址,否则可能导致无法使用"),placeholder:g("请输入到 /suno 前的路径,通常就是域名,例如:https://api.example.com\n支持多个地址负载均衡,每行一个"),onChange:e=>ot("base_url",e),autosize:{minRows:2,maxRows:6},showClear:!0})})]}),t.jsxs(L,{className:"!rounded-2xl shadow-sm border-0 mb-6",children:[t.jsxs("div",{className:"flex items-center mb-2",children:[t.jsx(J,{size:14,color:"purple",className:"mr-2 shadow-md",children:t.jsx(de,{size:16})}),t.jsxs("div",{children:[t.jsx(Be,{className:"text-lg font-medium",children:g("模型配置")}),t.jsx("div",{className:"text-xs text-gray-600",children:g("模型选择和映射设置")})]})]}),t.jsx(M.Select,{field:"models",label:g("模型"),placeholder:g("请选择该渠道所支持的模型"),rules:[{required:!0,message:g("请选择模型")}],dropdownClassName:qe,dropdownMatchSelectWidth:!0,dropdownStyle:R,autoAdjustOverflow:!0,onDropdownVisibleChange:V,multiple:!0,filter:!0,searchPosition:"dropdown",optionList:re,style:{width:"100%"},onChange:e=>ot("models",e),extraText:t.jsxs(z,{wrap:!0,children:[t.jsx(T,{size:"small",type:"primary",onClick:()=>ot("models",ye),children:g("填入相关模型")}),t.jsx(T,{size:"small",type:"secondary",onClick:()=>ot("models",fe),children:g("填入所有模型")}),t.jsx(T,{size:"small",type:"tertiary",onClick:()=>(async()=>{j(!0);const e=te.models||[];let t=!1;if(_){const s=await i.get("/api/channel/fetch_models/"+y,{skipErrorHandler:!0});s&&s.data&&s.data.success?e.push(...s.data.data):t=!0}else if(te?.key)try{const s=await i.post("/api/channel/fetch_models",{base_url:te.base_url,type:te.type,key:te.key},{skipErrorHandler:!0});s&&s.data&&s.data.success?e.push(...s.data.data):t=!0}catch(s){console.error("Error fetching models:",s),t=!0}else r(g("请填写密钥")),t=!0;t?r(g("获取模型列表失败")):(ot("models",Array.from(new Set(e))),o(g("获取模型列表成功"))),j(!1)})(),children:g("获取模型列表")}),t.jsx(T,{size:"small",type:"warning",onClick:()=>ot("models",[]),children:g("清除所有模型")}),t.jsx(T,{size:"small",type:"tertiary",onClick:()=>{if(0!==te.models.length)try{d(te.models.join(",")),o(g("模型列表已复制到剪贴板"))}catch(e){r(g("复制失败"))}else n(g("没有模型可以复制"))},children:g("复制所有模型")})]})}),t.jsx(M.Input,{field:"custom_model",label:g("自定义模型名称"),placeholder:g("输入自定义模型名称"),onChange:e=>be(e.trim()),value:ve,suffix:t.jsx(T,{size:"small",type:"primary",onClick:dt,children:g("填入")})}),t.jsx(M.Input,{field:"test_model",label:g("默认测试模型"),placeholder:g("不填则为模型列表第一个"),onChange:e=>ot("test_model",e),showClear:!0}),_&&t.jsx(T,{icon:t.jsx(he,{size:16}),type:"warning",theme:"solid",size:"large",onClick:()=>w(!0),style:{marginBottom:12,fontWeight:600},children:g("配置模型成本(必填)")}),t.jsx(Re,{channelId:y,models:te.models||[],isEdit:_,visible:b,onClose:()=>w(!1)}),t.jsx(M.TextArea,{field:"model_mapping",label:g("模型重定向"),placeholder:g("此项可选,用于修改请求体中的模型名称,为一个 JSON 字符串,键为请求中模型名称,值为要替换的模型名称,例如:")+`\n${JSON.stringify(Me,null,2)}`,autosize:!0,onChange:e=>ot("model_mapping",e),extraText:t.jsx(Be,{className:"!text-primary curs
1or-pointer",onClick:()=>ot("model_mapping",JSON.stringify(Me,null,2)),children:g("填入模板")}),showClear:!0}),t.jsx(M.TextArea,{field:"return_model_mapping",label:g("返回模型重定向"),placeholder:g("此项可选,用于修改返回体中的模型名称,为一个 JSON 字符串,键为返回中模型名称,值为要替换的模型名称,例如:")+`\n${JSON.stringify(Le,null,2)}`,autosize:!0,onChange:e=>ot("return_model_mapping",e),extraText:t.jsx(Be,{className:"!text-primary cursor-pointer",onClick:()=>ot("return_model_mapping",JSON.stringify(Le,null,2)),children:g("填入模板")}),showClear:!0}),t.jsx(M.TextArea,{field:"model_timeout_mapping",label:g("模型超时限制"),placeholder:g("此项可选,用于设置模型超时限制,为一个 JSON 字符串,键为模型名称,值为超时时间(秒),例如:")+`\n${JSON.stringify(We,null,2)}`,autosize:!0,onChange:e=>ot("model_timeout_mapping",e),extraText:t.jsx(Be,{className:"!text-primary cursor-pointer",onClick:()=>ot("model_timeout_mapping",JSON.stringify(We,null,2)),children:g("填入模板")}),showClear:!0}),t.jsx(M.Switch,{field:"trust_upstream_token",label:g("信任上游Token计费"),checkedText:g("是"),uncheckedText:g("否"),onChange:e=>it("trust_upstream_token",e),extraText:g("是否信任使用上游返回的 token 进行计费,关闭后将使用本地计算")})]}),t.jsxs(L,{className:"!rounded-2xl shadow-sm border-0 mb-6",children:[t.jsxs("div",{className:"flex items-center mb-2",children:[t.jsx(J,{size:14,color:"orange",className:"mr-2 shadow-md",children:t.jsx(me,{size:16})}),t.jsxs("div",{children:[t.jsx(Be,{className:"text-lg font-medium",children:g("高级设置")}),t.jsx("div",{className:"text-xs text-gray-600",children:g("渠道的高级配置选项")})]})]}),t.jsx(M.Select,{field:"groups",label:g("分组"),placeholder:g("请选择可以使用该渠道的分组"),multiple:!0,dropdownClassName:qe,dropdownMatchSelectWidth:!0,dropdownStyle:R,autoAdjustOverflow:!0,onDropdownVisibleChange:V,allowAdditions:!0,additionLabel:g("请在系统设置页面编辑分组倍率以添加新的分组:"),optionList:xe,style:{width:"100%"},onChange:e=>ot("groups",e),renderOptionItem:({disabled:e,selected:s,label:l,value:a,focused:i,className:r,style:n,onMouseEnter:o,onClick:c,empty:d,...h})=>{const m=xe.find(e=>e.value===a),p=m?.ratio||1,u=m?.description||"",x=p<=1?"green":p<=3?"blue":p<=7?"orange":"red";return t.jsxs("div",{style:{...n,display:"grid",gridTemplateColumns:"minmax(0, 1fr) auto",alignItems:"center",columnGap:12,width:"calc(100% - 8px)",maxWidth:"calc(100% - 8px)",boxSizing:"border-box",backgroundColor:i?"hsl(var(--foreground) / 0.02)":"transparent",color:"hsl(var(--foreground))",cursor:e?"not-allowed":"pointer",opacity:e?.5:1,borderRadius:4,margin:"2px 4px",padding:"8px 12px",transition:"background-color 0.1s ease",...Ke},onClick:()=>!e&&c(),onPointerEnter:e=>{"touch"!==e.pointerType&&o()},children:[t.jsxs("div",{className:"flex items-center min-w-0",children:[t.jsx("div",{className:"flex-shrink-0",style:{width:22,height:16,marginRight:8},children:s&&t.jsx("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",focusable:"false","aria-hidden":"true",children:t.jsx("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M21.35 4.27c.68.47.86 1.4.38 2.08l-10 14.5a1.5 1.5 0 0 1-2.33.17l-6.5-7a1.5 1.5 0 0 1 2.2-2.04l5.23 5.63 8.94-12.96a1.5 1.5 0 0 1 2.08-.38Z",fill:"currentColor"})})}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"text-sm font-medium truncate",children:a}),u&&t.jsx("div",{className:"text-xs mt-0.5 truncate",style:{color:"hsl(var(--muted-foreground))"},children:u})]})]}),t.jsxs(k,{color:x,size:"small",className:"flex-shrink-0 !m-0",children:[p,"倍"]})]})},renderSelectedItem:(e,{onClose:s})=>{const l=e?.value||e?.props?.value||e,a=xe.find(e=>e.value===l),i=a?.ratio||1,r=i<=1?"green":i<=3?"blue":i<=7?"orange":"red";return{isRenderInTag:!1,content:t.jsxs(k,{closable:!0,onClose:s,color:r,size:"small",className:"!px-2 !py-0.5 !mr-1 !mb-1",children:[t.jsx("span",{className:"font-medium",children:l}),t.jsx("span",{className:"opacity-75 mx-1",children:"·"}),t.jsxs("span",{className:"text-xs font-mono",children:[i,"倍"]})]})}}}),t.jsx(M.Input,{field:"tag",label:g("渠道标签"),placeholder:g("渠道标签"),showClear:!0,onChange:e=>ot("tag",e)}),t.jsxs(P,{gutter:12,children:[t.jsx(W,{span:12,children:t.jsx(M.InputNumber,{field:"priority",label:g("渠道优先级"),placeholder:g("渠道优先级"),min:0,onNumberChange:e=>ot("priority",e),style:{width:"100%"}})}),t.jsx(W,{span:12,children:t.jsx(M.InputNumber,{field:"weight",label:g("渠道权重"),placeholder:g("渠道权重"),min:0,onNumberChange:e=>ot("weight",e),style:{width:"100%"}})})]}),t.jsxs(P,{gutter:12,children:[t.jsx(W,{span:8,children:t.jsx(M.InputNumber,{field:"price",label:g("渠道价格"),placeholder:g("设置渠道的基础价格"),min:0,step:.
101,onNumberChange:e=>ot("price",e),style:{width:"100%"},extraText:g("可选,用于自定义渠道的价格计算")})}),t.jsx(W,{span:8,children:t.jsx(M.InputNumber,{field:"recharge_price",label:g("充值汇率"),placeholder:g("例如:1 表示 1元=1额度"),min:0,step:1e-4,precision:4,onNumberChange:e=>ot("recharge_price",void 0===e?null:e),style:{width:"100%"},extraText:g("上游平台充值汇率,修改后旧渠道将自动归档留底")})}),t.jsx(W,{span:8,children:t.jsx(M.InputNumber,{field:"group_ratio",label:g("分组倍率"),placeholder:g("例如:3 表示实际成本=充值汇率×3"),min:0,step:.01,precision:4,onNumberChange:e=>ot("group_ratio",void 0===e?null:e),style:{width:"100%"},extraText:g("上游分组价格倍率,实际成本 = 充值汇率 × 分组倍率,修改后旧渠道将自动归档留底")})})]}),t.jsx(M.Switch,{field:"auto_ban",label:g("是否自动禁用"),checkedText:g("开"),uncheckedText:g("关"),onChange:e=>{ee(e),ot("auto_ban",e)},extraText:g("仅当自动禁用开启时有效,关闭后不会自动禁用该渠道"),initValue:Q}),t.jsx(M.TextArea,{field:"param_override",label:g("参数覆盖"),placeholder:g("此项可选,用于覆盖请求参数。不支持覆盖 stream 参数")+"\n"+g("旧格式(直接覆盖):")+'\n{\n  "temperature": 0,\n  "max_tokens": 1000\n}\n\n'+g("新格式(支持条件判断与json自定义):")+'\n{\n  "operations": [\n    {\n      "path": "temperature",\n      "mode": "set",\n      "value": 0.7,\n      "conditions": [\n        {\n          "path": "model",\n          "mode": "prefix",\n          "value": "gpt"\n        }\n      ]\n    }\n  ]\n}',autosize:!0,onChange:e=>ot("param_override",e),extraText:t.jsxs("div",{className:"flex gap-2 flex-wrap",children:[t.jsx(Be,{className:"!text-primary cursor-pointer",onClick:()=>ot("param_override",JSON.stringify({temperature:0},null,2)),children:g("旧格式模板")}),t.jsx(Be,{className:"!text-primary cursor-pointer",onClick:()=>ot("param_override",JSON.stringify({operations:[{path:"temperature",mode:"set",value:.7,conditions:[{path:"model",mode:"prefix",value:"gpt"}],logic:"AND"}]},null,2)),children:g("新格式模板")})]}),showClear:!0}),t.jsx(M.TextArea,{field:"header_override",label:g("请求头覆盖"),placeholder:g("此项可选,用于覆盖发往上游的请求头")+"\n"+g("格式示例:")+'\n{\n  "User-Agent": "Mozilla/5.0 ...",\n  "Authorization": "Bearer {api_key}"\n}',autosize:!0,onChange:e=>ot("header_override",e),extraText:t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsxs("div",{className:"flex gap-2 flex-wrap",children:[t.jsx(Be,{className:"!text-primary cursor-pointer",onClick:()=>ot("header_override",JSON.stringify({"*":!0,"re:^X-Trace-.*$":!0,"X-Foo":"{client_header:X-Foo}",Authorization:"Bearer {api_key}","User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36"},null,2)),children:g("填入模板")}),t.jsx(Be,{className:"!text-primary cursor-pointer",onClick:()=>ot("header_override",JSON.stringify({"*":!0},null,2)),children:g("填入透传模板")}),t.jsx(Be,{className:"!text-primary cursor-pointer",onClick:()=>{const e="string"==typeof te.header_override?te.header_override.trim():"";if(e)try{ot("header_override",JSON.stringify(JSON.parse(e),null,2))}catch(t){n(g("请求头覆盖不是合法的 JSON 格式"))}},children:g("格式化")})]}),t.jsxs("div",{className:"text-xs",children:[t.jsx("span",{children:g("支持变量:")}),t.jsxs("span",{className:"ml-2 text-gray-500",children:[g("渠道密钥"),": ","{api_key}"]}),t.jsxs("span",{className:"ml-2 text-gray-500",children:[g("客户端请求头"),": ","{client_header:<名称>}"]})]})]}),showClear:!0}),t.jsx(M.TextArea,{field:"status_code_mapping",label:g("状态码复写"),placeholder:g("此项可选,用于复写返回的状态码,仅影响本地判断,不修改返回到上游的状态码,比如将claude渠道的400错误复写为500(用于重试),请勿滥用该功能,例如:")+"\n"+JSON.stringify(Je,null,2),autosize:!0,onChange:e=>ot("status_code_mapping",e),extraText:t.jsx(Be,{className:"!text-primary curs
1or-pointer",onClick:()=>ot("status_code_mapping",JSON.stringify(Je,null,2)),children:g("填入模板")}),showClear:!0})]}),t.jsxs(L,{className:"!rounded-2xl shadow-sm border-0 mb-6",children:[t.jsxs("div",{className:"flex items-center mb-2",children:[t.jsx(J,{size:14,color:"violet",className:"mr-2 shadow-md",children:t.jsx(oe,{size:16})}),t.jsxs("div",{children:[t.jsx(Be,{className:"text-lg font-medium",children:g("渠道额外设置")}),t.jsx("div",{className:"text-xs text-gray-600",children:g("渠道的特殊功能配置")})]})]}),1===te.type&&t.jsx(M.Switch,{field:"force_format",label:g("强制格式化"),checkedText:g("开"),uncheckedText:g("关"),onChange:e=>it("force_format",e),extraText:g("强制将响应格式化为 OpenAI 标准格式(只适用于OpenAI渠道类型)")}),t.jsx(M.Switch,{field:"thinking_to_content",label:g("思考内容转换"),checkedText:g("开"),uncheckedText:g("关"),onChange:e=>it("thinking_to_content",e),extraText:g("将 reasoning_content 转换为 <think> 标签拼接到内容中")}),t.jsx(M.Switch,{field:"pass_through_body_enabled",label:g("透传请求体"),checkedText:g("开"),uncheckedText:g("关"),onChange:e=>it("pass_through_body_enabled",e),extraText:g("启用请求体透传功能")}),t.jsx("div",{className:"text-sm font-medium mt-4 mb-1",children:g("字段透传控制")}),t.jsx(M.Switch,{field:"allow_service_tier",label:g("允许 service_tier 透传"),checkedText:g("开"),uncheckedText:g("关"),onChange:e=>rt("allow_service_tier",e),extraText:g("service_tier 字段用于指定服务层级,允许透传可能导致实际计费高于预期。默认关闭以避免额外费用")}),t.jsx(M.Switch,{field:"disable_store",label:g("store 字段透传"),checkedText:g("禁用"),uncheckedText:g("允许"),onChange:e=>rt("disable_store",e),extraText:g("store 字段默认允许透传,禁用后可能导致 Codex 无法正常使用")}),t.jsx(M.Input,{field:"proxy",label:g("代理地址"),placeholder:g("例如: socks5://user:pass@host:port"),onChange:e=>it("proxy",e),showClear:!0,extraText:g("用于配置网络代理,支持 socks5 协议")}),t.jsx(M.TextArea,{field:"system_prompt",label:g("系统提示词"),placeholder:g("输入系统提示词,用户的系统提示词将优先于此设置"),onChange:e=>it("system_prompt",e),autosize:!0,showClear:!0,extraText:g("用户优先:如果用户在请求中指定了系统提示词,将优先使用用户的设置")}),t.jsx(M.Switch,{field:"system_prompt_override",label:g("系统提示词拼接"),checkedText:g("开"),uncheckedText:g("关"),onChange:e=>it("system_prompt_override",e),extraText:g("如果用户请求中包含系统提示词,则使用此设置拼接到用户的系统提示词前面")}),t.jsx(M.TextArea,{field:"filter_fields",label:g("过滤返回字段"),placeholder:g("channel_placeholder_009"),onChange:e=>it("filter_fields",e),autosize:!0,showClear:!0,extraText:t.jsxs(z,{children:[t.jsx(Be,{type:"tertiary",size:"small",children:g("过滤API返回的字段,值为true表示过滤该字段,支持sjson路径语法")}),t.jsx(Be,{className:"!text-primary cursor-pointer",onClick:()=>it("filter_fields",JSON.stringify(De,null,2)),children:g("填入模板")})]})}),t.jsx(M.TextArea,{field:"claude_beta_filters",label:g("Claude Beta Flags 过滤"),placeholder:g("channel_placeholder_008"),onChange:e=>it("claude_beta_filters",e),autosize:!0,showClear:!0,extraText:g("过滤 Anthropic-Beta 请求头中的特定 flags,多个 flag 用英文逗号分隔")}),t.jsx(M.Switch,{field:"bedrock_compat",label:g("AWS Bedrock 兼容模式"),checkedText:g("开"),uncheckedText:g("关"),onChange:e=>it("bedrock_compat",e),extraText:g("channel_placeholder_001")}),t.jsx(M.Switch,{field:"retry_on_content_filter",label:g("内容过滤重试"),checkedText:g("开"),uncheckedText:g("关"),onChange:e=>it("retry_on_content_filter",e),extraText:g("当内容被审核过滤时(finish_reason=content_filter)触发429错误重试")}
1),t.jsx(M.TextArea,{field:"channel_rate_limit",label:g("渠道限流设置"),placeholder:g("channel_placeholder_007"),onChange:e=>it("channel_rate_limit",e),autosize:!0,showClear:!0,extraText:t.jsxs(z,{vertical:!0,align:"start",children:[t.jsxs(z,{children:[t.jsx(Be,{type:"tertiary",size:"small",children:g("渠道限流设置,当开启渠道限流时,自动填入默认值")}),t.jsx(Be,{className:"!text-primary cursor-pointer",onClick:()=>it("channel_rate_limit",JSON.stringify(Fe,null,2)),children:g("填入模板")})]}),t.jsx(Be,{type:"tertiary",size:"small",children:g("channel_placeholder_002")})]})})]}),t.jsxs(L,{className:"!rounded-2xl shadow-sm border-0 mb-6",children:[t.jsxs("div",{className:"flex items-center mb-4 p-6 rounded-xl",style:{background:"linear-gradient(135deg, #7c2d12 0%, #dc2626 50%, #ef4444 100%)",position:"relative"},children:[t.jsxs("div",{className:"absolute inset-0 overflow-hidden",children:[t.jsx("div",{className:"absolute -top-10 -right-10 w-40 h-40 bg-white opacity-5 rounded-full"}),t.jsx("div",{className:"absolute -bottom-8 -left-8 w-24 h-24 bg-white opacity-10 rounded-full"})]}),t.jsx("div",{className:"w-10 h-10 rounded-full bg-white/20 flex items-center justify-center mr-4 relative",children:t.jsx(me,{size:20,style:{color:"#ffffff"}})}),t.jsxs("div",{className:"relative",children:[t.jsx(Be,{style:{color:"#ffffff"},className:"text-lg font-medium",children:g("扩展功能")}),t.jsx("div",{style:{color:"#ffffff"},className:"text-sm opacity-80",children:g("二开版本的专属功能配置")})]})]}),t.jsx(M.InputNumber,{field:"failure_timeout_ban_limit",label:g("失败超时禁用限制时间(秒)"),placeholder:g("设置
1失败超时禁用限制时间"),min:0,onNumberChange:e=>ot("failure_timeout_ban_limit",e),style:{width:"100%"},extraText:g("当渠道连续失败达到此时间限制时自动禁用")})]})]})})}),t.jsx(D,{src:we,visible:Se,onVisibleChange:e=>Ce(e)})]})})},{Text:Ge,Title:Ye}=w,Ze={"gpt-3.5-turbo":"gpt-3.5-turbo-0125"},Xe={"gpt-4o":"gpt-4o-2024-08-06","gpt-3.5-turbo":"gpt-3.5-turbo-0125","gpt-4o-mini":"gpt-4o-mini-2024-07-18","o1-mini":"o1-mini-2024-09-12","o1-preview":"o1-preview-2024-09-12","gpt-4-turbo":"gpt-4-turbo-2024-04-09"},Qe=s=>{const{t:a}=l(),{visible:c,tag:d,handleClose:u,refresh:x}=s,[g,y]=e.useState(!1),[_,f]=e.useState([]),[j,v]=e.useState([]),[b,w]=e.useState([]),[S,C]=e.useState(""),N={tag:"",new_tag:null,model_mapping:null,return_model_mapping:null,header_override:null,groups:[],models:[]},[I,O]=e.useState(N),E=e.useRef(null),R=()=>({...N}),P=(e,t)=>{if(O(s=>({...s,[e]:t})),E.current&&E.current.setValue(e,t),"type"===e){let e=[];switch(t){case 2:e=["mj_imagine","mj_variation","mj_reroll","mj_blend","mj_upscale","mj_describe","mj_uploads"];break;case 5:e=["swap_face","mj_imagine","mj_video","mj_edits","mj_variation","mj_reroll","mj_blend","mj_upscale","mj_describe","mj_zoom","mj_shorten","mj_modal","mj_inpaint","mj_custom_zoom","mj_high_variation","mj_low_variation","mj_pan","mj_uploads"];break;case 36:e=["suno_music","suno_music_open","suno_lyrics"];break;default:e=h(t)}0===I.models.length&&O(t=>({...t,models:e}))}};e.useEffect(()=>{let e=[..._];I.models.forEach(t=>{e.find(e=>e.label===t)||e.push({label:t,value:t})}),v(e)},[_,I.models]),e.useEffect(()=>{(async()=>{try{let e=(await i.get("/api/channel/models")).data.data.map(e=>({label:e.id,value:e.id}));f(e)}catch(e){r(e.message)}})().then(),(async()=>{try{let e=await i.get("/api/group/");if(void 0===e)return;const t=e.data.data;t&&t.groups?w(t.groups.map(e=>({label:e,value:e}))):Array.isArray(t)&&w(t.map(e=>({label:e,value:e})))}catch(e){r(e.message)}})().then(),(async()=>{if(d){y(!0);try{const e=await i.get(`/api/channel/tag/models?tag=${d}`);if(e?.data?.success){const t=e.data.data?e.data.data.split(","):[];P("models",t)}else r(e.data.message)}catch(e){r(e.message)}finally{y(!1)}}})().then(),E.current&&E.current.setValues({...R(),tag:d,new_tag:d}),O({...N,tag:d,new_tag:d})},[c,d]),e.useEffect(()=>{E.current&&E.current.setValues(I)},[I]);const W=()=>{if(""===S.trim())return;const e=S.split(",").map(e=>e.trim());let t=[...I.models],s=[...j];const l=[];e.forEach(e=>{e&&!t.includes(e)&&(t.push(e),s.push({key:e,text:e,value:e}),l.push(e))}),v(s),C(""),P("models",t),l.length>0?o(a("已新增 {{num}} 个模型:{{list}}",{num:l.length,list:l.join(", ")})):n(a("未发现新增模型"))};return t.jsx(B,{placement:"right",title:t.jsxs(z,{children:[t.jsx(k,{color:"blue",shape:"circle",children:a("编辑")}),t.jsx(Ye,{heading:4,className:"m-0",children:a("编辑标签")})]}),bodyStyle:{padding:"0"},visible:c,width:600,onCancel:u,footer:t.jsx("div",{className:"flex justify-end bg-white",children:t.jsxs(z,{children:[t.jsx(T,{theme:"solid",onClick:()=>E.current?.submitForm(),loading:g,icon:t.jsx(le,{size:16}),children:a("保存")}),t.jsx(T,{theme:"light",type:"primary",onClick:u,icon:t.jsx(pe,{size:16}),children:a("取消")})]})}),closeIcon:null,children:t.jsx(M,{initValues:R(),getFormApi:e=>E.current=e,onSubmit:async e=>{y(!0);const t=e||E.current?.getValues()||{};let s={tag:d};if(t.model_mapping){if(!p(t.model_mapping))return n(a("模型映射必须是合法的 JSON 格式!")),void y(!1);s.model_mapping=t.model_mapping}if(null!==I.return_model_mapping&&""!==I.return_model_mapping){if(""!==I.return_model_mapping&&!p(I.return_model_mapping))return n(a("返回模型重定向必须是合法的 JSON 格式!")),void y(!1);s.return_model_mapping=I.return_model_mapping}if(t.groups&&t.groups.length>0&&(s.groups=t.groups.join(",")),t.models&&t.models.length>0&&(s.models=t.models.join(",")),void 0!==t.header_override&&null!==t.header_override){if("string"!=typeof t.header_override)return n(a("请求头覆盖必须是合法的 JSON 格式!")),void y(!1);const e=t.header_override.trim();if(""!==e&&!p(e))return n(a("请求头覆盖必须是合法的 JSON 格式!")),void y(!1);s.header_override=e}if(s.new_tag=t.new_tag,void 0===s.model_mapping&&void 0===s.return_model_mapping&&void 0===s.groups&&void 0===s.models&&void 0===s.header_override&&void 0===s.new_tag)return m(a("没有任何修改!")),void y(!1);await(async e=>{try{const t=await i.put("/api/channel/tag",e);t?.data?.success&&(o(a("标签更新成功!")),x(),u())}catch(t){r(t)}})(s),y(!1)},children:()=>t.jsx(A,{spinning:g,children:t.jsxs("div",{className:"p-2",children:[t.jsxs(L,{className:"!rounded-2xl shadow-sm border-0 mb-6",children:[t.jsxs("div",{className:"flex items-center mb-2",children:[t.jsx(J,{size:14,color:"blue",className:"mr-2 shadow-md",children:t.jsx(ue,{size:16})}),t.jsxs("div",{children:[t.jsx(Ge,{className:"text-lg font-medium",children:a("标签信息")}),t.jsx("div",{className:"text-xs text-gray-600",children:a("标签的基本配置")})]})]}),t.jsx($,{type:"warning",description:a("所有编辑均为覆盖操作,留空则不更改"),className:"!rounded-lg mb-4"}),t.jsx("div",{className:"space-y-4",children:t.jsx(M.Input,{field:"new_tag",label:a("标签名称"),placeholder:a("请输入新标签,留空则解散标签"),onChange:e=>P("new_tag",e)})})]}),t.jsxs(L,{className:"!rounded-2xl shadow-sm border-0 mb-6",children:[t.jsxs("div",{className:"flex items-center mb-2",children:[t.jsx(J,{size:14,color:"purple",className:"mr-2 shadow-md",children:t.jsx(de,{size:16})}),t.jsxs("div",{children:[t.jsx(Ge,{className:"text-lg font-medium",children:a("模型配置")}),t.jsx("div",{className:"text-xs text-gray-600",children:a("模型选择和映射设置")})]})]}),t.jsxs("div",{className:"space-y-4",children:[t.jsx($,{type:"info",description:a("当前模型列表为该标签下所有渠道模型列表最长的一个,并非所有渠道的并集,请注意可能导致某些渠道模型丢失。"),className:"!rounded-lg mb-4"}),t.jsx(M.Select,{field:"models",label:a("模型"),placeholder:a("请选择该渠道所支持的模型,留空则不更改"),multiple:!0,filter:!0,searchPosition:"dropdown",optionList:j,style:{width:"100%"},onChange:e=>P("models",e)}),t.jsx(M.Input,{field:"custom_model",label:a("自定义模型名称"),placeholder:a("输入自定义模型名称"),onChange:e=>C(e.trim()),suffix:t.jsx(T,{size:"small",type:"primary",onClick:W,children:a("填入")})}),t.jsx(M.TextArea,{field:"model_mapping",label:a("模型重定向"),placeholder:a("此项可选,用于修改请求体中的模型名称,为一个 JSON 字符串,键为请求中模型名称,值为要替换的模型名称,留空则不更改"),autosize:!0,value:
1I.model_mapping,onChange:e=>P("model_mapping",e),extraText:t.jsxs(z,{children:[t.jsx(Ge,{className:"!text-primary cursor-pointer",onClick:()=>P("model_mapping",JSON.stringify(Ze,null,2)),children:a("填入模板")}),t.jsx(Ge,{className:"!text-primary cursor-pointer",onClick:()=>P("model_mapping",JSON.stringify({},null,2)),children:a("清空重定向")}),t.jsx(Ge,{className:"!text-primary cursor-pointer",onClick:()=>P("model_mapping",""),children:a("不更改")})]})}),t.jsx(M.TextArea,{field:"return_model_mapping",label:a("返回模型重定向"),placeholder:a("此项可选,用于修改返回体中的模型名称,为一个 JSON 字符串,键为返回中模型名称,值为要替换的模型名称,留空则不更改"),autosize:!0,value:I.return_model_mapping,onChange:e=>P("return_model_mapping",e),extraText:t.jsxs(z,{children:[t.jsx(Ge,{className:"!text-primary cursor-pointer",onClick:()=>P("return_model_mapping",JSON.stringify(Xe,null,2)),children:a("填入模板")}),t.jsx(Ge,{className:"!text-primary cursor-pointer",onClick:()=>P("return_model_mapping",JSON.stringify({},null,2)),children:a("清空重定向")}),t.jsx(Ge,{className:"!text-primary cursor-pointer",onClick:()=>P("return_model_mapping",""),children:a("不更改")})]})})]})]}),t.jsxs(L,{className:"!rounded-2xl shadow-sm border-0",children:[t.jsxs("div",{className:"flex items-center mb-2",children:[t.jsx(J,{size:14,color:"green",className:"mr-2 shadow-md",children:t.jsx(xe,{size:16})}),t.jsxs("div",{children:[t.jsx(Ge,{className:"text-lg font-medium",children:a("分组设置")}),t.jsx("div",{className:"text-xs text-gray-600",children:a("用户分组配置")})]})]}),t.jsx("div",{className:"space-y-4",children:t.jsx(M.Select,{field:"groups",label:a("分组"),placeholder:a("请选择可以使用该渠道的分组,留空则不更改"),multiple:!0,allowAdditions:!0,additionLabel:a("请在系统设置页面编辑分组倍率以添加新的分组:"),optionList:b,style:{width:"100%"},onChange:e=>P("groups",e)})})]}),t.jsxs(L,{className:"!rounded-2xl shadow-sm border-0 mt-6",children:[t.jsxs("div",{className:"flex items-center mb-2",children:[t.jsx(J,{size:14,color:"orange",className:"mr-2 shadow-md",children:t.jsx(de,{size:16})}),t.jsxs("div",{children:[t.jsx(Ge,{className:"text-lg font-medium",children:a("请求头覆盖")}),t.jsx("div",{className:"text-xs text-gray-600",children:a("批量设置标签下渠道的请求头覆盖")})]})]}),t.jsx(M.TextArea,{field:"header_override",label:a("请求头覆盖"),placeholder:a("此项可选,用于覆盖请求头参数")+"\n"+a("格式示例:")+'\n{\n  "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36",\n  "Authorization": "Bearer {api_key}"\n}',autosize:!0,showClear:!0,onChange:e=>P("header_override",e),extraText:t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsxs(z,{children:[t.jsx(Ge,{className:"!text-primary cursor-pointer",onClick:()=>P("header_override",JSON.stringify({"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36",Authorization:"Bearer {api_key}"},null,2)),children:a("填入模板")}),t.jsx(Ge,{className:"!text-primary cursor-pointer",onClick:()=>P("header_override",null),children:a("不更改")})]}),t.jsxs("div",{className:"text-xs text-tertiary",children:[t.jsx("div",{children:a("支持变量:")}),t.jsxs("div",{className:"ml-2",children:[a("渠道密钥"),": ","{api_key}"]}),t.jsxs("div",{className:"ml-2",children:[a("客户端请求头"),": ","{client_header:<名称>}"]})]})]})})]})]})})},d||"edit")})};function et(e){return be({attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M504.971 359.029c9.373 9.373 9.373 24.569 0 33.941l-80 79.984c-15.01 15.01-40.971 4.49-40.971-16.971V416h-58.785a12.004 12.004 0 0 1-8.773-3.812l-70.556-75.596 53.333-57.143L352 336h32v-39.981c0-21.438 25.943-31.998 40.971-16.971l80 79.981zM12 176h84l52.781 56.551 53.333-57.143-70.556-75.596A11.999 11.999 0 0 0 122.785 96H12c-6.627 0-12 5.373-12 12v56c0 6.627 5.373 12 12 12zm372 0v39.984c0 21.46 25.961 31.98 40.971 16.971l80-79.984c9.373-9.373 9.373-24.569 0-33.941l-80-79.981C409.943 24.021 384 34.582 384 56.019V96h-58.785a12.004 12.004 0 0 0-8.773 3.812L96 336H12c-6.627 0-12 5.373-12 12v56c0 6.627 5.373 12 12 12h110.785c3.326 0 6.503-1.381 8.773-3.812L352 176h32z"},child:[]}]})(e)}const tt=({visible:s,onCancel:a,channelId:n,channelName:o})=>{const{t:c}=l(),[d,h]=e.useState(!1),[m,p]=e.useState([]),[u,x]=e.useState(""),[g,y]=e.useState("24h"),[_,f]=e.useState(null),[j,v]=e.useState(null);e.useEffect(()=>{s&&n&&b()},[s,n]);const b=async()=>{try{const e=await i.get(`/api/channel/${n}`);if(e.data.success&&e.data.data){const t=e.data.data;if(t.models&&t.models.length>0){const e=t.models.split(",").map(e=>e.trim()).filter(e=>e);p(e),e.length>0&&!u&&x(e[0])}}}catch(e){console.error("获取渠道模型列表失败:",e)}};e.useEffect(()=>{u&&n&&w()},[u,g,n]);const w=async()=>{h(!0);try{const e=await i.get(`/api/channel/success_rate_trend?channel_id=${n}&model=${u}&period=${g}`);if(e.data.success){const t=e.data.data;f(t),S(t)}else r(e.data.message||c("获取数据失败"))}catch(e){r(c("获取成功率趋势数据失败")),console.error("fetchTrendData error:",e)}finally{h(!1)}},S=e=>{if(!e||!e.data_points||0===e.data_points.length)return void v(null);const t={type:"line",data:[{id:"data",values:e.data_points.map(e=>({time:e.time_label,success_rate:parseFloat((100*e.success_rate).toFixed(2)),total_requests:e.total_requests}))}],xField:"time",yField:"success_rate",line:{style:{lineWidth:3,lineCap:"round",stroke:"#4CC9F0"}},point:{style:{size:6,fill:"white",stroke:"#4CC9F0",lineWidth:2}},axes:[{orient:"left",type:"linear",title:{visible:!0,text:c("成功率")+" (%)",style:{fontSize:12}},min:0,max:100,grid:{visible:!0}},{orient:"bottom",type:"band",label:{autoRotate:!0,autoRotateAngle:[0,45,90]}}],title:{visible:!0,text:c("成功率趋势"),textStyle:{fontSize:16,fontWeight:"bold"}},tooltip:{mark:{content:[{key:e=>c("时间"),value:e=>e.time},{key:e=>c("成功率"),value:e=>`${e.success_rate}%`},{key:e=>c("总请求数"),value:e=>e.total_requests}]}},legends:{visible:!1}};v(t)};return t.jsxs(N,{title:t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx(ge,{size:16}),t.jsxs("span",{children:[c("成功率趋势分析")," - ",o]})]}),visible:s,onCancel:a,footer:null,width:900,bodyStyle:{padding:"24px"}
1,children:[t.jsxs("div",{style:{marginBottom:"16px",display:"flex",gap:"12px",alignItems:"center"},children:[t.jsxs("div",{style:{flex:1},children:[t.jsxs("span",{style:{marginRight:"8px"},children:[c("选择模型"),":"]}),t.jsx(C,{value:u,onChange:x,style:{width:"300px"},filter:!0,placeholder:c("请选择模型"),children:m.map(e=>t.jsx(C.Option,{value:e,children:e},e))})]}),t.jsxs("div",{children:[t.jsxs("span",{style:{marginRight:"8px"},children:[c("时间范围"),":"]}),t.jsxs(C,{value:g,onChange:y,style:{width:"120px"},children:[t.jsx(C.Option,{value:"24h",children:c("最近24小时")}),t.jsx(C.Option,{value:"7d",children:c("最近7天")})]})]}),t.jsx(T,{icon:t.jsx(se,{size:16}),onClick:()=>{u&&w()},disabled:!u,children:c("刷新")})]}),d?t.jsxs("div",{style:{textAlign:"center",padding:"60px 0"},children:[t.jsx(A,{size:20}),t.jsxs("div",{style:{marginTop:"16px",color:"#999"},children:[c("加载中..."),"..."]})]}):u?_&&j?t.jsxs(t.Fragment,{children:[t.jsx(L,{style:{marginBottom:"16px"},bodyStyle:{padding:"16px"},children:t.jsxs(V,{row:!0,children:[t.jsx(V.Item,{itemKey:c("平均成功率"),children:t.jsx(k,{color:_.summary.avg_success_rate>=.9?"green":_.summary.avg_success_rate>=.7?"orange":"red",size:"large",children:(z=_.summary.avg_success_rate,`${(100*z).toFixed(2)}%`)})}),t.jsx(V.Item,{itemKey:c("总请求数"),children:_.summary.total_requests}),t.jsx(V.Item,{itemKey:c("成功请求"),children:t.jsx("span",{style:{color:"#52c41a"},children:_.summary.success_requests})}),t.jsx(V.Item,{itemKey:c("失败请求"),children:t.jsx("span",{style:{color:"#ff4d4f"},children:_.summary.failure_requests})})]})}),t.jsx("div",{style:{height:"400px",marginTop:"16px"},children:t.jsx(ke,{spec:j})})]}):t.jsx(E,{description:c("暂无数据"),style:{padding:"60px 0"}}):t.jsx(E,{description:c("请先选择要分析的模型"),style:{padding:"60px 0"}})]});var z},st=()=>{const{t:s}=l(),c=a(),h=e.useRef(!1);let m;const p=(e,l=void 0)=>{if(!m){m=new Map;for(let e=0;e<v.length;e++)m[v[e].value]=v[e];m[0]={value:0,label:s("未知类型"),color:"grey"}}let a=u(e);return l?.is_multi_key&&(a="random"===l?.multi_key_mode?t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(et,{className:"text-blue-500"}),a]}):t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(je,{size:16,className:"text-blue-500"}),a]})),t.jsx(k,{color:m[e]?.color,shape:"circle",prefixIcon:a,children:m[e]?.label})},$=(e,l=void 0)=>{if(l&&l.is_multi_key){let t=l.multi_key_size,s=t;return l.multi_key_status_list&&(s=t-Object.keys(l.multi_key_status_list).length),J(e,t,s)}switch(e){case 1:return t.jsx(k,{color:"green",shape:"circle",children:s("已启用")});case 2:return t.jsx(k,{color:"red",shape:"circle",children:s("已禁用")});case 3:return t.jsx(k,{color:"yellow",shape:"circle",children:s("自动禁用")});case 4:return t.jsx(k,{color:"teal",shape:"circle",children:s("对账完毕")});case 5:return t.jsx(k,{color:"grey",shape:"circle",children:s("价格归档")});case 6:return t.jsx(k,{color:"red",shape:"circle",children:s("渠道商封禁")});default:return t.jsx(k,{color:"grey",shape:"circle",children:s("未知状态")})}},J=(e,l,a)=>{switch(e){case 1:return t.jsxs(k,{color:"green",shape:"circle",children:[s("已启用")," ",a,"/",l]});case 2:return t.jsxs(k,{color:"red",shape:"circle",children:[s("已禁用")," ",a,"/",l]});case 3:return t.jsxs(k,{color:"yellow",shape:"circle",children:[s("自动禁用")," ",a,"/",l]});default:return t.jsxs(k,{color:"grey",shape:"circle",children:[s("未知状态")," ",a,"/",l]})}},P=e=>{if(2!==e.status&&3!==e.status)return null;try{const t=JSON.parse(e.other_info||"{}"),s=t.status_reason;if(!s)return null;const l=t.status_operator||"",a=t.status_time;let i="";if(a){const e=new Date(1e3*a);i=`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")} ${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}`}return{reason:s,operator:l,timeStr:i}}catch(t){return null}},W=e=>{if(c||!ms)return null;const s=P(e);return s?t.jsx("div",{style:{marginTop:"4px",fontSize:"12px",color:"hsl(var(--muted-foreground))",lineHeight:"1.4",wordBreak:"break-word",whiteSpace:"normal",maxWidth:"200px"},children:s.reason}):null},D=(e,l)=>{N.info({title:s("禁用原因"),hasCancel:!1,okText:s("知道了"),centered:!0,width:"calc(100vw - 48px)",style:{maxWidth:480},content:t.jsxs("div",{style:{fontSize:"13px",lineHeight:1.6,wordBreak:"break-word"},children:[(e.operator||e.timeStr)&&t.jsxs("div",{style:{display:"flex",gap:12,marginBottom:10,fontSize:"12px",color:"hsl(var(--muted-foreground))",borderBottom:"1px solid hsl(var(--border))",paddingBottom:8},children:[e.operator&&t.jsx("span",{children:e.operator}
1),e.timeStr&&t.jsx("span",{children:e.timeStr})]}),t.jsx("div",{style:{color:l,maxHeight:"40vh",overflowY:"auto",whiteSpace:"pre-wrap",fontSize:"13px",lineHeight:1.6},children:e.reason})]})})},F=e=>{let l=e/1e3;return l=s("{{seconds}} 秒",{seconds:l.toFixed(2)}),0===e?t.jsx(k,{color:"grey",shape:"circle",children:s("未测试")}):e<=1e3?t.jsx(k,{color:"green",shape:"circle",children:l}):e<=3e3?t.jsx(k,{color:"lime",shape:"circle",children:l}):e<=5e3?t.jsx(k,{color:"yellow",shape:"circle",children:l}):t.jsx(k,{color:"red",shape:"circle",children:l})},V={ID:"id",NAME:"name",GROUP:"group",TYPE:"type",STATUS:"status",DISABLE_REASON:"disable_reason",DISABLED_BY:"disabled_by",DISABLED_AT:"disabled_at",RESPONSE_TIME:"response_time",BALANCE:"balance",PRIORITY:"priority",WEIGHT:"weight",PRICE:"price",OPERATE:"operate"},[se,le]=e.useState({}),[ae,ie]=e.useState(!1),[re,ne]=e.useState(x()?localStorage.getItem("channel-status-filter")||"price_archived":localStorage.getItem("channel-status-filter")||"all");e.useEffect(()=>{const e=localStorage.getItem("channels-table-columns");if(e)try{const t=JSON.parse(e),s={...oe(),...t};le(s)}catch(t){console.error("Failed to parse saved column preferences",t),ce()}else ce()},[]),e.useEffect(()=>{Object.keys(se).length>0&&localStorage.setItem("channels-table-columns",JSON.stringify(se))},[se]);const oe=()=>({[V.ID]:!0,[V.NAME]:!0,[V.GROUP]:!0,[V.TYPE]:!0,[V.STATUS]:!0,[V.DISABLE_REASON]:!0,[V.DISABLED_BY]:!0,[V.DISABLED_AT]:!0,[V.RESPONSE_TIME]:!0,[V.BALANCE]:!0,[V.PRIORITY]:!0,[V.WEIGHT]:!0,[V.PRICE]:!0,[V.OPERATE]:!0}),ce=()=>{const e=oe();le(e)},de=[{key:V.ID,title:s("ID"),dataIndex:"id"},{key:V.NAME,title:s("名称"),dataIndex:"name",width:200,render:(e,l)=>t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx(S,{content:s("点击复制渠道名称"),children:t.jsx("span",{style:{wordBreak:"break-all",cursor:"pointer"},onClick:()=>d(e).then(e=>e?o(s("已复制渠道名称")):r(s("复制失败"))),children:e})}),1===l.is_synced&&t.jsx(S,{content:s("此渠道从其他系统同步而来"),children:t.jsx(k,{color:"blue",size:"small",style:{marginLeft:"4px"},children:s("同步")})})]})},{key:V.GROUP,title:s("分组"),dataIndex:"group",width:220,render:(e,s,l)=>t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"2px"},children:e?.split(",").sort((e,t)=>"default"===e?-1:"default"===t?1:e.localeCompare(t)).map((e,t)=>g(e))})},{key:V.TYPE,title:s("类型"),dataIndex:"type",render:(e,l,a)=>void 0===l.children?l.channel_info&&l.channel_info.is_multi_key?t.jsx(t.Fragment,{children:p(e,l.channel_info)}):t.jsx(t.Fragment,{children:p(e)}):t.jsx(t.Fragment,{children:t.jsx(k,{color:"light-blue",shape:"circle",type:"light",children:s("标签聚合")})})},{key:V.STATUS,title:s("状态"),dataIndex:"status",width:140,render:(e,s,l)=>t.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"flex-start"},children:[$(e,s.channel_info),!c&&W(s)]})},{key:V.DISABLE_REASON,title:s("禁用原因"),dataIndex:"other_info",render:(e,l)=>{if(2!==l.status&&3!==l.status)return c?null:"-";const a=P(l);return a?c?(e=>{if(2!==e.status&&3!==e.status)return null;const l=P(e);if(!l)return null;const a=3===e.status?"hsl(var(--warning))":"hsl(var(--destructive))",i=l.reason.length>16?l.reason.slice(0,16)+"…":l.reason;return t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"4px",fontSize:"12px",lineHeight:"1.4",width:"100%"},children:[t.jsx("span",{style:{color:a,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i}),t.jsx("span",{style:{color:"hsl(var(--primary))",cursor:"pointer",whiteSpace:"nowrap",marginLeft:8,flexShrink:0},onClick:e=>{e.stopPropagation(),D(l,a)},children:s("点击查看")})]})})(l):t.jsx("div",{style:{fontSize:"12px",color:"hsl(var(--muted-foreground))",lineHeight:"1.4",wordBreak:"break-word",maxWidth:"200px"},children:a.reason}):c?null:"-"}},{key:V.DISABLED_BY,title:s("禁用人"),dataIndex:"other_info",render:(e,s)=>{const l=P(s);return l?.operator?t.jsx("span",{style:{fontSize:"13px"},children:l.operator}):c?null:"-"}},{key:V.DISABLED_AT,title:s("禁用时间"),dataIndex:"other_info",render:(e,s)=>{const l=P(s);return l?.timeStr?t.jsx("span",{style:{fontSize:"13px",whiteSpace:"nowrap"},children:l.timeStr}):c?null:"-"}},{key:V.RESPONSE_TIME,title:s("响应时间"),dataIndex:"response_time",render:(e,s,l)=>t.jsx("div",{children:F(e)})},{key:V.BALANCE,title:s("已用/剩余"),dataIndex:"expired_time",render:(e,l,a)=>void 0===l.children?t.jsx("div",{children:t.jsxs(z,{spacing:1,children:[t.jsx(S,{content:s("点击复制已用额度"),children:t.jsx(k,{color:"white",type:"ghost",shape:"circle",style:{cursor:"pointer"},onClick:()=>{const e=y(l.used_quota);d(e).then(e=>e?o(s("已复制已用额度")):r(s("复制失败")))},children:y(l.used_quota)})}),t.jsx(S,{content:s("剩余额度{{balance}},点击更新",{balance:l.balance}),children:t.jsx(k,{color:"white",type:"ghost",shape:"circle",onClick:()=>fl(l),children:_(l.balance)})})]})}):t.jsx(S,{content:s("点击复制已用额度"),children:t.jsx(k,{color:"white",type:"ghost",shape:"circle",style:{cursor:"pointer"},onClick:()=>{const e=y(l.used_quota);d(e).then(e=>e?o(s("已复制已用额度")):r(s("复制失败")))},children:y(l.used_quota)})})},{key:V.PRIORITY,title:s("优先级"),dataIndex:"priority",render:(e,l,a)=>void 0===l.children?t.jsx("div",{children:t.jsx(I,{style:{width:70},name:"priority",onBlur:e=>{sl(l.id,"priority",l,e.target.value)},keepFocus:!0,innerButtons:!0,defaultValue:l.priority,min:-999,size:"small"})}):t.jsx(I,{style:{width:70},name:"priority",keepFocus:!0,onBlur:e=>{N.warning({title:s("修改子渠道优先级"),content:s("确定要修改所有子渠道优先级为 {{value}} 吗?",{value:e.target.value}),onOk:()=>{""!==e.target.value&&pl("priority",{tag:l.key,priority:e.target.value})}})},innerButtons:!0,defaultValue:l.priority,min:-999,size:"small"})},{key:V.WEIGHT,title:s("权重"),dataIndex:"weight",render:(e,l,a)=>void 0===l.children?t.jsx("div",{children:t.jsx(I,{style:{width:70},name:"weight",onBlur:e=>{sl(l.id,"weight",l,e.target.value)},keepFocus:!0,innerButtons:!0,defaultValue:l.weight,min:0,size:"small"})}):t.jsx(I,{style:{width:70},name:"weight",keepFocus:!0,onBlur:e=>{N.warning({title:s("修改子渠道权重"),content:s("确定要修改所有子渠道权重为 {{value}} 吗?",{value:e.target.value}),onOk:()=>{""!==e.target.value&&pl("weight",{tag:l.key,weight:e.target.value})}})},innerButtons:!0,defaultValue:l.weight,min:-999,size:"small"})},{key:V.PRICE,title:s("成本核算"),dataIndex:"recharge_price",render:(e,l,a)=>{if(void 0!==l.children)return null;const i=null!=l.recharge_price?l.recharge_price:"-",r=null!=l.group_ratio?l.group_ratio:"-",n=null!=l.price?l.price:"-";return t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[t.jsxs("div",{style:{fontSize:12,lineHeight:"1.5"},children:[t.jsx("div",{style:{marginBottom:2},children:(()=>{const e=l.model_cost_count||0,a=l.model_total_count||0;if(a>0&&e>=a)return t.jsx("span",{style:{fontSize:11,color:"#16a34a",background:"rgba(22,163,74,0.12)",borderRadius:4,padding:"1px 6px"},children:s("全部已配置")});if(e>0){const l=Math.max(a-e,0);return t.jsxs("span",{style:{fontSize:11,color:"#d97706",background:"rgba(217,119,6,0.12)",borderRadius:4,padding:"1px 6px"},children:[s("已配")," ",e,"/",a," · ",s("还差")," ",l]})}return t.jsxs("span",{style:{fontSize:11,color:"hsl(var(--muted-foreground))",background:"hsl(var(--muted))",borderRadius:4,padding:"1px 6px"},children:[s("未配成本"),a>0?` · ${s("还差")}
1 ${a}`:""]})})()}),t.jsxs("div",{children:[t.jsxs("span",{style:{color:"hsl(var(--muted-foreground))"},children:[s("充值汇率"),":"]}),t.jsx("span",{style:{marginLeft:4,fontWeight:500},children:i})]}),t.jsxs("div",{children:[t.jsxs("span",{style:{color:"hsl(var(--muted-foreground))"},children:[s("分组倍率"),":"]}),t.jsx("span",{style:{marginLeft:4,fontWeight:500},children:r})]}),t.jsxs("div",{children:[t.jsxs("span",{style:{color:"hsl(var(--muted-foreground))"},children:[s("排序价格"),":"]}),t.jsx("span",{style:{marginLeft:4,fontWeight:500},children:n})]})]}),t.jsx(T,{size:"small",theme:"borderless",onClick:()=>{cs(l),hs({recharge_price:null!=l.recharge_price?l.recharge_price:1,group_ratio:null!=l.group_ratio?l.group_ratio:1}),ns(!0)},children:s("修改")})]})}},{key:V.OPERATE,title:"",dataIndex:"operate",fixed:"right",render:(e,l,a)=>{if(void 0===l.children){const e=[{node:"item",name:s("成功率"),onClick:()=>{It(l),zt(!0)}},{node:"item",name:s("删除"),type:"danger",onClick:()=>{N.confirm({title:s("确定是否要删除此渠道?"),content:s("此修改将不可逆"),onOk:()=>{(async()=>{await sl(l.id,"delete",l),await tl(),setTimeout(()=>{0===me.length&&ge>1&&tl(ge-1)},100)})()}})}},{node:"item",name:s("复制"),type:"tertiary",onClick:()=>{N.confirm({title:s("确定是否要复制此渠道?"),content:s("复制渠道的所有信息"),onOk:()=>el(l)})}}];if(c){const a={width:"100%",borderRadius:"8px",flex:1};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"6px",width:"100%",flex:1},children:[!x()&&t.jsxs(K,{style:{...a,display:"flex",alignItems:"stretch",width:"100%"},"aria-label":s("测试单个渠道操作项目组"),children:[t.jsx(T,{type:"primary",theme:"light",style:{flex:1,height:"100%"},onClick:()=>nl(l,""),children:s("测试")}),t.jsx(T,{type:"primary",theme:"light",icon:t.jsx(ye,{size:16}),style:{padding:"0 12px",height:"100%"},onClick:()=>{jt(l),_t(!0)}})]}),!x()&&(1===l.status?t.jsx(T,{size:"small",type:"danger",theme:"light",style:a,onClick:()=>sl(l.id,"disable",l),children:s("禁用")}):t.jsx(T,{size:"small",type:"primary",theme:"light",style:a,onClick:()=>sl(l.id,"enable",l),children:s("启用")})),!x()&&l.channel_info?.is_multi_key&&t.jsx(T,{size:"small",type:"tertiary",style:a,onClick:()=>sl(l.id,"enable_all",l),children:s("启用全部密钥")}),x()&&5===l.status&&t.jsx(T,{size:"small",type:"primary",theme:"light",style:a,onClick:()=>{N.confirm({title:s("确认标记对账完毕?"),content:s("将渠道「{{name}}」标记为对账完毕后不可撤销",{name:l.name}),onOk:async()=>{const e=await i.put(`/api/channel/reconcile/${l.id}`),{success:t,message:a}=e.data;t?(o(s("已标记为对账完毕")),await tl()):r(a)}})},children:s("标记对账")}),!x()&&t.jsx(T,{size:"small",type:"tertiary",style:a,onClick:()=>{Pe(l),$e(!0)},children:s("编辑")}),!x()&&t.jsx(T,{size:"small",type:"warning",theme:"light",style:a,icon:t.jsx(he,{size:14}),onClick:()=>{Ve(l),De(!0)},children:s("成本")}),!x()&&e.map((e,s)=>t.jsx(T,{size:"small",style:a,type:"danger"===e.type?"danger":"tertiary",theme:"danger"===e.type?"light":void 0,onClick:e.onClick,children:e.name},s))]})}return t.jsxs(z,{wrap:!0,children:[!x()&&t.jsxs(K,{className:"overflow-hidden","aria-label":s("测试单个渠道操作项目组"),children:[t.jsx(T,{size:"small",type:"tertiary",onClick:()=>nl(l,""),children:s("测试")}),t.jsx(T,{size:"small",type:"tertiary",icon:t.jsx(ye,{size:16}),onClick:()=>{jt(l),_t(!0)}})]}),x()&&5===l.status&&t.jsx(T,{size:"small",type:"primary",theme:"light",onClick:()=>{N.confirm({title:s("确认标记对账完毕?"),content:s("将渠道「{{name}}」标记为对账完毕后不可撤销",{name:l.name}),onOk:async()=>{const e=await i.put(`/api/channel/reconcile/${l.id}`),{success:t,message:a}=e.data;t?(o(s("已标记为对账完毕")),await tl()):r(a)}})},children:s("标记对账")}),!x()&&(l.channel_info?.is_multi_key?t.jsxs(K,{"aria-label":s("多密钥渠道操作项目组"),children:[1===l.status?t.jsx(T,{type:"danger",size:"small",onClick:()=>sl(l.id,"disable",l),children:s("禁用")}):t.jsx(T,{size:"small",onClick:()=>sl(l.id,"enable",l),children:s("启用")}),t.jsx(q,{trigger:"click",position:"bottomRight",menu:[{node:"item",name:s("启用全部密钥"),onClick:()=>sl(l.id,"enable_all",l)}],children:t.jsx(T,{type:"tertiary",size:"small",icon:t.jsx(ye,{size:16})})})]}):1===l.status?t.jsx(T,{type:"danger",size:"small",onClick:()=>sl(l.id,"disable",l),children:s("禁用")}):t.jsx(T,{size:"small",onClick:()=>sl(l.id,"enable",l),children:s("启用")})),!x()&&t.jsx(T,{type:"tertiary",size:"small",onClick:()=>{Pe(l),$e(!0)},children:s("编辑")}),!x()&&t.jsx(S,{content:s("配置模型成本"),children:t.jsx(T,{icon:t.jsx(he,{size:14}),type:"warning",theme:"light",size:"small",onClick:()=>{Ve(l),De(!0)}})}),!x()&&t.jsx(q,{trigger:"click",position:"bottomRight",menu:e,children:t.jsx(T,{icon:t.jsx(_e,{size:16}),type:"tertiary",size:"small"})})]})}return t.jsxs(z,{wrap:!0,children:[t.jsx(T,{type:"tertiary",size:"small",onClick:()=>ll(l.key,"enable"),children:s("启用全部")}
1),t.jsx(T,{type:"tertiary",size:"small",onClick:()=>ll(l.key,"disable"),children:s("禁用全部")}),t.jsx(T,{type:"tertiary",size:"small",onClick:()=>{qe(!0),Ge(l.key)},children:s("编辑")})]})}}],[me,pe]=e.useState([]),[ue,xe]=e.useState(!0),[ge,be]=e.useState(1),[ke,Se]=e.useState(!1),[Ce,Ne]=e.useState(!1),[ze,Te]=e.useState(f),[Ie,Oe]=e.useState(ze),[Ae,Ee]=e.useState([]),[Be,$e]=e.useState(!1),[Me,Le]=e.useState(!1),[Je,Pe]=e.useState({id:void 0}),[We,De]=e.useState(!1),[Fe,Ve]=e.useState(null),[Ke,qe]=e.useState(!1),[Ue,Ge]=e.useState(""),[Ye,Ze]=e.useState([]),[Xe,st]=e.useState(!1),[lt,at]=e.useState(!1),[it,rt]=e.useState(""),[nt,ot]=e.useState(!1),[ct,dt]=e.useState(""),[ht,mt]=e.useState(""),[pt,ut]=e.useState(!1),[xt,gt]=e.useState(""),[yt,_t]=e.useState(!1),[ft,jt]=e.useState(null),[vt,bt]=e.useState(""),[wt,kt]=e.useState(""),[St,Ct]=e.useState(!1),[Nt,zt]=e.useState(!1),[Tt,It]=e.useState(null),[Ot,At]=e.useState({}),[Et,Rt]=e.useState(new Set),[Bt,$t]=e.useState([]),[Mt,Lt]=e.useState(!1),[Jt,Pt]=e.useState([]),[Wt,Dt]=e.useState(!1),[Ft,Vt]=e.useState(1),[Kt,qt]=e.useState("all"),[Ut,Ht]=e.useState({}),Gt=e.useRef(0),[Yt,Zt]=e.useState(null),[Xt,Qt]=ve("channels"),[es,ts]=e.useState(!1),[ss,ls]=e.useState(""),[as,is]=e.useState(null),[rs,ns]=e.useState(!1),[os,cs]=e.useState(null),[ds,hs]=e.useState({recharge_price:null,group_ratio:null}),[ms,ps]=e.useState(!1),[us,xs]=e.useState([]),[gs,ys]=e.useState(!1),_s=e.useCallback(async()=>{try{const e=await i.get("/api/smart_sorting/banned_models");e.data.success&&xs(e.data.data||[])}catch(e){}},[]),fs=e.useCallback(async(e,t)=>{try{const l=await i.post("/api/smart_sorting/unban_model",{channel_id:e,model_name:t});l.data.success?(o(s("已解除禁用")),_s()):r(l.data.message)}catch(l){r(s("操作失败"))}},[s,_s]),js=e.useCallback(async()=>{try{const e=await i.post("/api/smart_sorting/unban_all_models");e.data.success?(o(s("已全部解除,共")+" "+(e.data.data||0)+" "+s("个")),_s()):r(e.data.message)}catch(e){r(s("操作失败"))}},[s,_s]);e.useEffect(()=>{const e="true"===localStorage.getItem("show-disable-reason");ps(e),_s()},[_s]);const vs=e.useRef(!1),[bs,ws]=e.useState(!1),[ks,Ss]=e.useState(null),[Cs,Ns]=e.useState(null),zs=e.useRef(null),[Ts,Is]=e.useState(!1),[Os,As]=e.useState(""),[Es,Rs]=e.useState(""),[Bs,$s]=e.useState(!1),[Ms,Ls]=e.useState(!1),[Js,Ps]=e.useState(null),[Ws,Ds]=e.useState([]),[Fs,Vs]=e.useState(!1),[Ks,qs]=e.useState(null),[Us,Hs]=e.useState(null),[Gs,Ys]=e.useState(!1),Zs=()=>de.filter(e=>!(!se[e.key]||!c&&e.key===V.DISABLE_REASON&&!ms)),Xs=(e,t)=>{let s=[],l={};for(let a=0;a<e.length;a++)if(e[a].key=""+e[a].id,t){let t,i=e[a].tag?e[a].tag:"";void 0===l[i]?(l[i]=1,t={key:i,id:i,tag:i,name:"标签:"+i,group:"",used_quota:0,response_time:0,priority:-1,weight:-1},t.children=[],s.push(t)):t=s.find(e=>e.key===i),-1===t.priority?t.priority=e[a].priority:t.priority!==e[a].priority&&(t.priority=""),-1===t.weight?t.weight=e[a].weight:t.weight!==e[a].weight&&(t.weight=""),""===t.group?t.group=e[a].group:e[a].group.split(",").forEach((e,s)=>{-1===t.group.indexOf(e)&&(t.group+=","+e)}),t.children.push(e[a]),1===e[a].status&&(t.status=1),t.used_quota+=e[a].used_quota,t.response_time+=e[a].response_time,t.response_time=t.response_time/2}else s.push(e[a]);pe(s)},Qs=async(e,t,s,l,a=Kt,n)=>{void 0===n&&(n=re);const{searchKeyword:o,searchGroup:c,searchModel:d}=al();if(""!==o||""!==c||""!==d)return xe(!0),await il(l,a,n,e,t,s),void xe(!1);const h=++Gt.current;xe(!0);const m="all"!==a?`&type=${a}`:"",p="all"!==n?`&status=${n}`:"",u=await i.get(`/api/channel/?p=${e}&page_size=${t}&id_sort=${s}&tag_mode=${l}${m}${p}`);if(void 0===u||h!==Gt.current)return;const{success:x,message:g,data:y}=u.data;if(x){const{items:e,total:t,type_counts:s}=y;if(s){const e=Object.values(s).reduce((e,t)=>e+t,0);Ht({...s,all:e})}Xs(e,l),Oe(t)}else r(g);xe(!1)},el=async e=>{try{const t=await i.post(`/api/channel/copy/${e.id}`);t?.data?.success?(o(s("渠道复制成功")),await tl()):r(t?.data?.message||s("渠道复制失败"))}catch(t){r(s("渠道复制失败:{{message}}",{message:t?.response?.data?.message||t?.message||t}))}},tl=async(e=ge)=>{const{searchKeyword:t,searchGroup:s,searchModel:l}=al();""===t&&""===s&&""===l?await Qs(e,ze,ke,Xe):await il(Xe,Kt,re,e,ze,ke),_s()};e.useEffect(()=>{const e="true"===localStorage.getItem("id-sort"),t=parseInt(localStorage.getItem("page-size"))||f,s="true"===localStorage.getItem("enable-tag-mode"),l="true"===localStorage.getItem("enable-batch-delete");Se(e),Te(t),st(s),Le(l),Qs(1,t,e,s).then().catch(e=>{r(e)}),ml().then(),j().then()},[]);const sl=async(e,t,l,a)=>{let n,c={id:e};switch(t){case"delete":n=await i.delete(`/api/channel/${e}/`);break;case"enable":c.status=1,n=await i.put("/api/channel/",c);break;case"disable":return is({id:e,record:l}),ls(""),void ts(!0);case"priority":if(""===a)return;c.priority=parseInt(a),n=await i.put("/api/channel/",c);break;case"weight":if(""===a)return;c.weight=parseInt(a),c.weight<0&&(c.weight=0),n=await i.put("/api/channel/",c);break;case"price":if(""===a)return;c.price=parseFloat(a),c.price<0&&(c.price=0),n=await i.put("/api/channel/",c);break;case"enable_all":c.channel_info=l.channel_info,c.channel_info.multi_key_status_list={},n=await i.put("/api/channel/",c)}const{success:d,message:h}=n.data;if(d){o(s("操作成功完成!"));let e=n.data.data,a=[...me];"delete"===t||(l.status=e.status),pe(a)}else r(h)},ll=async(e,t)=>{let l;switch(t){case"enable":l=await i.post("/api/channel/tag/enabled",{tag:e});break;case"disable":l=await i.post("/api/channel/tag/disabled",{tag:e})}const{success:a,message:n}=l.data;if(a){o(s("操作成功完成!"));let l=[...me];for(let s=0;s<l.length;s++)if(l[s].tag===e){let e="enable"===t?1:2;l[s]?.children?.forEach(t=>{t.status=e}),l[s].status=e}pe(l)}else r(n)},al=()=>{const e=Yt?Yt.getValues():{};return{searchKeyword:e.searchKeyword||"",searchGroup:e.searchGroup||"",searchModel:e.searchModel||""}},il=async(e,t=Kt,s=re,l=1,a=ze,n=ke)=>{const{searchKeyword:o,searchGroup:c,searchModel:d}=al();Ne(!0);try{if(""===o&&""===c&&""===d)return void(await Qs(l,a,n,e,t,s));const h="all"!==t?`&type=${t}`:"",m="all"!==s?`&status=${s}`:"",p=await i.get(`/api/channel/search?keyword=${o}&group=${c}&model=${d}&id_sort=${n}&tag_mode=${e}&p=${l}&page_size=${a}${h}${m}`),{success:u,message:x,data:g}=p.data;if(u){const{items:t=[],total:s=0,type_counts:a={}}=g,i=Object.values(a).reduce((e,t)=>
1e+t,0);Ht({...a,all:i}),Xs(t,e),Oe(s),be(l)}else r(x)}finally{Ne(!1)}},rl=(e,t)=>{const s=[...me];let l=!1;s.forEach(s=>{void 0!==s.children?s.children.forEach(s=>{s.id===e&&(t(s),l=!0)}):s.id===e&&(t(s),l=!0)}),l&&pe(s)};e.useEffect(()=>{Jt.length>0&&Wt?(async()=>{if(!Wt||0===Jt.length)return;const{channel:e,model:t,indexInFiltered:l,endpointType:a,stream:o}=Jt[0];if(ft&&ft.id===e.id){let e;if(void 0!==l)e=Math.floor(l/b)+1;else{const s=ft.models.split(",").filter(e=>e.toLowerCase().includes(vt.toLowerCase())).indexOf(t);e=-1!==s?Math.floor(s/b)+1:1}Vt(e)}try{Rt(e=>new Set([...e,t]));let l=`/api/channel/test/${e.id}?model=${t}`;a&&(l+=`&endpoint_type=${encodeURIComponent(a)}`),o&&(l+="&stream=true");const c=await i.get(l),{success:d,message:h,time:m}=c.data;At(s=>({...s,[`${e.id}-${t}`]:{success:d,time:m}})),d?(rl(e.id,e=>{e.response_time=1e3*m,e.test_time=Date.now()/1e3}),t||n(s("通道 {{name}} 测试成功,耗时 {{time}} 秒。",{name:e.name,time:m.toFixed(2)}))):r(h)}catch(c){r(c.message)}finally{Rt(e=>{const s=new Set(e);return s.delete(t),s})}Pt(e=>e.slice(1))})():0===Jt.length&&Wt&&(Dt(!1),Lt(!1))},[Jt,Wt]);const nl=async(e,t,s="",l=!1)=>{Pt(a=>[...a,{channel:e,model:t,endpointType:s,stream:l}]),Wt||Dt(!0)},ol=()=>{Mt?(Pt([]),Dt(!1),Lt(!1),o(s("已停止测试"))):(_t(!1),bt(""),$t([]),Vt(1),kt(""),Ct(!1))},cl=e.useMemo(()=>{if(Object.keys(Ut).length>0)return Ut;const e={all:me.length};return me.forEach(t=>{const s=t=>{const s=t.type;e[s]=(e[s]||0)+1};void 0!==t.children?t.children.forEach(s):s(t)}),e},[Ut,me]),dl=e.useMemo(()=>{const e=["all"];return Object.entries(cl).forEach(([t,s])=>{"all"!==t&&s>0&&e.push(String(t))}),e},[cl]);let hl=me;const ml=async()=>{try{let e=await i.get("/api/group/");if(void 0===e)return;const t=e.data.data;t&&t.groups?Ee(t.groups.map(e=>({label:e,value:e}))):Array.isArray(t)&&Ee(t.map(e=>({label:e,value:e})))}catch(e){r(e.message)}},pl=async(e,t)=>{switch(e){case"priority":if(void 0===t.priority||""===t.priority)return void n(s("优先级必须是整数!"));t.priority=parseInt(t.priority);break;case"weight":if(void 0===t.weight||t.weight<0||""===t.weight)return void n(s("权重必须是非负整数!"));t.weight=parseInt(t.weight)}try{const e=await i.put("/api/channel/tag",t);e?.data?.success&&(o(s("更新成功")+"!"),await tl())}catch(l){r(l)}},ul=async e=>{ws(!0),Is(!1);const{searchKeyword:t,searchGroup:l,searchModel:a}=al();let n=[];try{const e="all"!==Kt?`&type=${Kt}`:"",s="all"!==re?`&status=${re}`:"";let o;o=""!==t||""!==l||""!==a?await i.get(`/api/channel/search?keyword=${t}&group=${l}&model=${a}&id_sort=${ke}&tag_mode=false&p=1&page_size=9999${e}${s}`):await i.get(`/api/channel/?p=1&page_size=9999&id_sort=${ke}&tag_mode=false${e}${s}`);const{success:c,message:d,data:h}=o.data;if(!c)return r(d),void ws(!1);n=(h.items||[]).filter(e=>void 0===e.children)}catch(c){return r(c.message),void ws(!1)}if(0===n.length)return r(s("没有找到符合条件的渠道")),void ws(!1);const o=n.map(t=>({channel_id:t.id,model:e||""}));try{const e=await i.post("/api/channel/batch_test",{items:o}),{success:t,message:s,data:l}=e.data;if(!t)return r(s),void ws(!1);Ss(l.task_id),Ns(l),$s(!0),qs(l.task_id),Hs(l),xl(l.task_id)}catch(c){r(c.message),ws(!1)}},xl=e=>{zs.current&&clearInterval(zs.current),zs.current=setInterval(async()=>{try{const t=await i.get(`/api/channel/batch_test/${e}`),{success:l,data:a}=t.data;if(!l)return clearInterval(zs.current),void ws(!1);Hs(a),Ns(a),"done"===a.status&&(clearInterval(zs.current),ws(!1),o(s("批量测试完成!成功 {{s}} 个,失败 {{f}} 个",{s:a.succeeded,f:a.failed})),gl())}catch(t){clearInterval(zs.current),ws(!1)}},1500)},gl=async()=>{Vs(!0);try{const e=await i.get("/api/channel/batch_test_list"),{success:t,data:s}=e.data;t&&Ds(s||[])}catch(e){}finally{Vs(!1)}},yl=()=>{$s(!0),gl()},_l=(e,l,a=!0)=>t.jsx("div",{className:"py-1"+(e.success?"":" cursor-pointer"),style:{borderBottom:"1px solid hsl(var(--border))",fontSize:12},onClick:e.success?void 0:()=>Ps(e),children:c?t.jsxs("div",{className:"flex flex-col gap-0.5",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(k,{color:e.success?"green":"red",size:"small",children:e.success?s("成功"):s("失败")}),t.jsx(w.Text,{size:"small",strong:!0,ellipsis:!0,style:{maxWidth:160},children:e.channel_name}),a&&t.jsxs(w.Text,{size:"small",type:"secondary",children:["#",e.channel_id]})]}),t.jsxs("div",{className:"flex items-center justify-between gap-2 pl-1",children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsx(k,{size:"small",color:"blue",children:e.model}),e.success?t.jsxs(w.Text,{size:"small",type:"tertiary",children:[e.time.toFixed(2),"s"]}):t.jsx(w.Text,{size:"small",type:"danger",ellipsis:!0,style:{maxWidth:160},children:e.message})]}),!e.success&&t.jsxs(w.Text,{size:"small",type:"danger",style:{flexShrink:0},children:[s("查看")," ›"]}
1)]})]}):t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(k,{color:e.success?"green":"red",size:"small",children:e.success?s("成功"):s("失败")}),t.jsx(w.Text,{size:"small",strong:!0,children:e.channel_name}),a&&t.jsxs(w.Text,{size:"small",type:"secondary",children:["#",e.channel_id]}),t.jsx(k,{size:"small",color:"blue",children:e.model}),e.success?t.jsxs(w.Text,{size:"small",type:"tertiary",children:[e.time.toFixed(2),"s"]}):t.jsx(S,{content:e.message,children:t.jsx(w.Text,{size:"small",type:"danger",ellipsis:!0,style:{maxWidth:200,cursor:"pointer"},children:e.message})})]})},l);e.useEffect(()=>{if(c&&Bs){const e=window.scrollY;return document.body.style.position="fixed",document.body.style.top=`-${e}px`,document.body.style.width="100%",document.body.style.overflowY="scroll",()=>{document.body.style.position="",document.body.style.top="",document.body.style.width="",document.body.style.overflowY="",window.scrollTo(0,e)}}},[Bs,c]);const fl=async e=>{const t=await i.get(`/api/channel/update_balance/${e.id}/`),{success:l,message:a,balance:o}=t.data;l?(rl(e.id,e=>{e.balance=o,e.balance_updated_time=Date.now()/1e3}),n(s("通道 {{name}} 余额更新成功!",{name:e.name}))):r(a)};return t.jsxs(t.Fragment,{children:[t.jsxs(N,{title:s("列设置"),visible:ae,onCancel:()=>ie(!1),footer:t.jsxs("div",{className:"flex justify-end",children:[t.jsx(T,{onClick:()=>ce(),children:s("重置")}),t.jsx(T,{onClick:()=>ie(!1),children:s("取消")}),t.jsx(T,{onClick:()=>ie(!1),children:s("确定")})]}),children:[t.jsx("div",{style:{marginBottom:20},children:t.jsx(O,{checked:Object.values(se).every(e=>!0===e),indeterminate:Object.values(se).some(e=>!0===e)&&!Object.values(se).every(e=>!0===e),onChange:e=>(e=>{const t=Object.keys(V).map(e=>V[e]),s={};t.forEach(t=>{s[t]=e}),le(s)})(e.target.checked),children:s("全选")})}),t.jsx("div",{className:"flex flex-wrap max-h-96 overflow-y-auto rounded-lg p-4",style:{border:"1px solid hsl(var(--border))"},children:de.map(e=>e.title?t.jsx("div",{className:"w-1/2 mb-4 pr-2",children:t.jsx(O,{checked:!!se[e.key],onChange:t=>((e,t)=>{const s={...se,[e]:t};le(s)})(e.key,t.target.checked),children:e.title})},e.key):null)})]}),t.jsx(Qe,{visible:Ke,tag:Ue,handleClose:()=>qe(!1),refresh:tl}),t.jsx(He,{refresh:tl,visible:Be,handleClose:()=>{$e(!1)},editingChannel:Je}),Fe&&t.jsx(Re,{channelId:Fe.id,models:Fe.models?Fe.models.split(","):[],isEdit:!0,visible:We,onClose:()=>{De(!1),Ve(null),tl()}}),us.length>0&&t.jsxs("div",{className:"mb-3",style:{borderRadius:12,borderLeft:"4px solid hsl(var(--destructive))",background:"hsl(var(--card))",boxShadow:"var(--app-shadow-md)",overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 16px",cursor:"pointer",userSelect:"none",flexWrap:"wrap",gap:8},onClick:()=>ys(e=>!e),children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[t.jsx("span",{style:{color:"hsl(var(--destructive))",fontWeight:600,fontSize:14,transition:"transform 0.2s",display:"inline-block",transform:gs?"rotate(90deg)":"rotate(0deg)",flexShrink:0},children:"▶"}),t.jsx("span",{style:{color:"hsl(var(--destructive))",fontWeight:600,whiteSpace:"nowrap"},children:s("临时禁用的模型")}),t.jsx(k,{color:"red",size:"small",shape:"circle",children:us.length})]}),t.jsxs("div",{style:{display:"flex",gap:8},onClick:e=>e.stopPropagation(),children:[t.jsx(T,{size:"small",type:"tertiary",onClick:_s,children:s("刷新")}),t.jsx(T,{size:"small",type:"danger",onClick:()=>{N.confirm({title:s("确认全部解除"),content:s("将解除所有临时禁用并重置升级计数,确定继续?"),onOk:js,centered:!0})},children:s("全部解除")})]})]}),gs&&t.jsxs("div",{style:{padding:"0 16px 12px"},children:[t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(280px, 1fr))",gap:6},children:us.map((e,l)=>t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",background:"hsl(var(--destructive) / 0.12)",borderRadius:6,padding:"6px 10px",gap:8,fontSize:13,lineHeight:1.4,minWidth:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,minWidth:0,flexWrap:"wrap"},children:[t.jsx(S,{content:s("点击复制渠道ID"),children:t.jsxs("span",{style:{cursor:"pointer",fontWeight:600,color:"hsl(var(--destructive))",whiteSpace:"nowrap"},onClick:()=>d(String(e.channel_id)).then(t=>t&&o(s("已复制")+": "+e.channel_id)),children:["#",e.channel_id]})}),e.channel_name&&t.jsx(S,{content:s("点击复制渠道名"),children:t.jsx("span",{style:{cursor:"pointer",color:"hsl(var(--muted-foreground))",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:120},onClick:()=>d(e.channel_name).then(t=>t&&o(s("已复制")+": "+e.channel_name)),children:e.channel_name})}),t.jsx("span",{style:{color:"hsl(var(--muted-foreground) / 0.60)"},children:"/"}),t.jsx(S,{content:s("点击复制模型名"),children:t.jsx("span",{style:{cursor:"pointer",fontWeight:500,color:"hsl(var(--destructive))",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},onClick:()=>d(e.model_name).then(t=>t&&o(s("已复制")+": "+e.model_name)),children:e.model_name})}),e.ttl>0&&t.jsxs("span",{style:{opacity:.6,fontSize:11,whiteSpace:"nowrap",flexShrink:0},children:[Math.ceil(e.ttl/60),s("分钟")]})]}),t.jsx(T,{size:"small",type:"danger",theme:"borderless",style:{flexShrink:0,padding:"0 4px"},onClick:()=>fs(e.channel_id,e.model_name),children:s("解除")})]},`${e.channel_id}-${e.model_name}-${l}`))}),t.jsx(w.Text,{type:"tertiary",size:"small",style:{display:"block",marginTop:8},children:s("连续超时后被临时禁用,到期自动恢复。反复超时将自动延长禁用时间。点击可复制,右侧按钮解除禁用并重置升级。")})]})]}),t.jsx(L,{className:"!rounded-2xl channel-table-card-toolbar-host",title:t.jsxs("div",{className:"flex flex-col w-full",children:[Xe?null:t.jsxs(ee,{activeKey:Kt,type:"card",collapsible:!0,onChange:e=>{qt(e),be(1),Qs(1,ze,ke,Xe,e)},className:"mb-4",children:[t.jsx(te,{itemKey:"all",tab:t.jsxs("span",{className:"flex items-center gap-2",children:[s("全部"),t.jsx(k,{color:"all"===Kt?"red":"grey",shape:"circle",children:cl.all||0})]})}),v.filter(e=>dl.includes(String(e.value))).map(e=>
1{const s=String(e.value),l=cl[e.value]||0;return t.jsx(te,{itemKey:s,tab:t.jsxs("span",{className:"flex items-center gap-2",children:[u(e.value),e.label,t.jsx(k,{color:Kt===s?"red":"grey",shape:"circle",children:l})]})},s)})]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2 w-full min-w-0",children:[!x()&&t.jsx(T,{size:"small",disabled:!Me,type:"danger",className:"order-2 md:order-1 "+(c?"w-full basis-full shrink-0":"shrink-0 w-auto max-w-full"),onClick:()=>{N.confirm({title:s("确定是否要删除所选通道?"),content:s("此修改将不可逆"),onOk:()=>(async()=>{if(0===Ye.length)return void r(s("请先选择要删除的通道!"));xe(!0);let e=[];Ye.forEach(t=>{e.push(t.id)});const t=await i.post("/api/channel/batch",{ids:e}),{success:l,message:a,data:n}=t.data;l?(o(s("已删除 ${data} 个通道!").replace("${data}",n)),await tl(),setTimeout(()=>{0===me.length&&ge>1&&tl(ge-1)},100)):r(a),xe(!1)})()})},children:s("删除所选通道")}),!x()&&t.jsx(T,{size:"small",disabled:!Me,type:"tertiary",onClick:()=>at(!0),className:"order-2 md:order-1 "+(c?"w-full basis-full shrink-0":"shrink-0 w-auto max-w-full"),children:s("批量设置标签")}),!x()&&t.jsx(T,{size:"small",type:"tertiary",onClick:()=>ot(!0),className:"order-2 md:order-1 "+(c?"w-full basis-full shrink-0":"shrink-0 w-auto max-w-full"),children:s("批量追加模型")}),!x()&&t.jsx(T,{size:"small",type:"tertiary",onClick:()=>ut(!0),className:"order-2 md:order-1 "+(c?"w-full basis-full shrink-0":"shrink-0 w-auto max-w-full"),children:s("批量移除模型")}),!x()&&t.jsx(q,{className:"order-2 md:order-1",size:"small",trigger:"click",render:t.jsxs(q.Menu,{children:[t.jsx(q.Item,{children:t.jsx(T,{size:"small",type:"tertiary",className:"w-full",onClick:()=>{N.confirm({title:s("确定")+"?",content:s("确定要测试所有通道吗?"),onOk:()=>(async()=>{const e=await i.get("/api/channel/test"),{success:t,message:l}=e.data;t?n(s("已成功开始测试所有已启用通道,请刷新页面查看结果。")):r(l)})(),size:"small",centered:!0})},children:s("测试所有通道")})}),t.jsx(q.Item,{children:t.jsx(T,{size:"small",className:"w-full",onClick:()=>{N.confirm({title:s("确定是否要修复数据库一致性?"),content:s("进行该操作时,可能导致渠道访问错误,请仅在数据库出现问题时使用"),onOk:()=>(async()=>{const e=await i.post("/api/channel/fix"),{success:t,message:l,data:a}=e.data;t?(o(s("已修复 ${success} 个通道,失败 ${fails} 个通道。").replace("${success}",a.success).replace("${fails}",a.fails)),await tl()):r(l)})(),size:"sm",centered:!0})},children:s("修复数据库一致性")})}),t.jsx(q.Item,{children:t.jsx(T,{size:"small",type:"secondary",className:"w-full",onClick:()=>{N.confirm({title:s("确定")+"?",content:s("确定要更新所有已启用通道余额吗?"),onOk:()=>(async()=>{const e=await i.get("/api/channel/update_balance"),{success:t,message:l}=e.data;t?n(s("已更新完毕所有已启用通道余额!")):r(l)})(),size:"sm",centered:!0})},children:s("更新所有已启用通道余额")})}),t.jsx(q.Item,{children:t.jsx(T,{size:"small",type:"danger",className:"w-full",onClick:()=>{N.confirm({title:s("确定是否要删除禁用通道?"),content:s("此修改将不可逆"),onOk:()=>(async()=>{const e=await i.delete("/api/channel/disabled"),{success:t,message:l,data:a}=e.data;t?(o(s("已删除所有禁用渠道,共计 {{num}} 个",{num:a})),await tl()):r(l)})(),size:"sm",centered:!0})},children:s("删除禁用通道")})})]}),children:t.jsx(T,{size:"small",theme:"light",type:"tertiary",className:c?"w-full basis-full shrink-0":"shrink-0 w-auto max-w-full",children:s("批量操作")})}),t.jsx(T,{size:"small",type:"tertiary",className:"order-2 md:order-1 "+(c?"w-full basis-full shrink-0":"shrink-0 w-auto max-w-full"),onClick:()=>Qt(!Xt),children:s(Xt?"自适应列表":"紧凑列表")}),!c&&t.jsxs("div",{className:"flex items-center gap-2 shrink-0 w-full sm:w-auto order-1 md:order-2",children:[t.jsx(w.Text,{strong:!0,children:s("显示禁用原因")}),t.jsx(Y,{size:"small",checked:ms,onChange:e=>{ps(e),localStorage.setItem("show-disable-reason",e+"")}})]}),t.jsxs("div",{className:"flex items-center gap-2 shrink-0 w-full sm:w-auto order-1 md:order-2",children:[t.jsx(w.Text,{strong:!0,children:s("使用ID排序")}),t.jsx(Y,{size:"small",checked:ke,onChange:e=>{localStorage.setItem("id-sort",e+""),Se(e);const{searchKeyword:t,searchGroup:s,searchModel:l}=al();""===t&&""===s&&""===l?Qs(ge,ze,e,Xe):il(Xe,Kt,re,ge,ze,e)}})]}),!x()&&t.jsxs("div",{className:"flex items-center gap-2 shrink-0 w-full sm:w-auto order-1 md:order-2",children:[t.jsx(w.Text,{strong:!0,children:s("开启批量操作")}
1),t.jsx(Y,{size:"small",checked:Me,onChange:e=>{localStorage.setItem("enable-batch-delete",e+""),Le(e)}})]}),t.jsxs("div",{className:"flex items-center gap-2 shrink-0 w-full sm:w-auto order-1 md:order-2",children:[t.jsx(w.Text,{strong:!0,children:s("标签聚合模式")}),t.jsx(Y,{size:"small",checked:Xe,onChange:e=>{localStorage.setItem("enable-tag-mode",e+""),st(e),be(1),Qs(1,ze,ke,e)}})]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2 shrink-0 w-full sm:w-auto min-w-0 order-1 md:order-2",children:[t.jsx(w.Text,{strong:!0,className:"shrink-0",children:s("状态筛选")}),t.jsxs(C,{size:"small",className:"shrink-0 w-full min-w-0 sm:w-auto sm:min-w-[168px] max-w-full",value:re,onChange:e=>{localStorage.setItem("channel-status-filter",e),ne(e),be(1),Qs(1,ze,ke,Xe,Kt,e)},children:[t.jsx(C.Option,{value:"all",children:s("全部")}),t.jsx(C.Option,{value:"enabled",children:s("已启用")}),t.jsx(C.Option,{value:"disabled",children:s("已禁用")}),t.jsx(C.Option,{value:"auto_disabled",children:s("自动禁用")}),t.jsx(C.Option,{value:"reconciled",children:s("对账完毕")}),t.jsx(C.Option,{value:"price_archived",children:s("价格归档")})]})]})]}),t.jsx(Q,{margin:"12px"}),t.jsxs("div",{className:"flex flex-col lg:flex-row lg:justify-between lg:items-center gap-4 w-full",children:[t.jsxs("div",{className:"flex flex-wrap gap-2 w-full lg:w-auto order-2 lg:order-1",children:[!x()&&t.jsx(T,{size:"small",theme:"light",type:"primary",onClick:()=>{Pe({id:void 0}),$e(!0)},children:s("添加渠道")}),t.jsx(T,{size:"small",type:"tertiary",onClick:tl,children:s("刷新")}),c?t.jsx(q,{trigger:"custom",visible:Ms,onVisibleChange:Ls,position:"bottomLeft",render:t.jsxs(q.Menu,{children:[t.jsx(q.Item,{onClick:()=>{Ls(!1),ie(!0)},children:s("列设置")}),!x()&&t.jsx(q.Item,{disabled:bs,onClick:()=>{bs||(Ls(!1),As(al().searchModel||""),Rs(""),Is(!0))},children:s(bs?"测试中...":"批量测试")}),t.jsx(q.Item,{onClick:()=>{Ls(!1),yl()},children:s("测试记录")})]}),children:t.jsx(T,{size:"small",type:"tertiary",icon:t.jsx(_e,{size:16}),onClick:()=>Ls(e=>!e),children:s("更多")})}):t.jsxs(t.Fragment,{children:[t.jsx(T,{size:"small",type:"tertiary",onClick:()=>ie(!0),children:s("列设置")}),!x()&&t.jsx(T,{size:"small",type:"tertiary",loading:bs,disabled:bs,onClick:()=>{bs||(As(al().searchModel||""),Rs(""),Is(!0))},children:s("批量测试")}),t.jsx(T,{size:"small",type:"tertiary",onClick:yl,children:s("测试记录")})]})]}),t.jsx("div",{className:"flex flex-col lg:flex-row lg:items-center gap-4 w-full lg:w-auto order-1 lg:order-2",children:t.jsxs(M,{initValues:{searchKeyword:"",searchGroup:"",searchModel:""},getFormApi:e=>Zt(e),onSubmit:()=>il(Xe),allowEmpty:!0,autoComplete:"on",layout:"horizontal",trigger:"change",stopValidateWithError:!1,className:"flex flex-col lg:flex-row lg:items-center gap-4 w-full",children:[t.jsx("div",{className:"relative w-full lg:w-64",children:t.jsx(M.Input,{size:"small",field:"searchKeyword",name:"channels_search_keyword",prefix:t.jsx(fe,{size:16}),placeholder:s("渠道ID,名称,密钥,API地址"),showClear:!0,pure:!0})}),t.jsx("div",{className:"w-full lg:w-48",children:t.jsx(M.Input,{size:"small",field:"searchModel",name:"channels_search_model",prefix:t.jsx(fe,{size:16}),placeholder:s("模型关键字"),showClear:!0,pure:!0})}),t.jsx("div",{className:"w-full lg:w-48",children:t.jsx(M.Select,{size:"small",filter:!0,field:"searchGroup",placeholder:s("选择分组"),optionList:[{label:s("选择分组"),value:null},...Ae],className:"w-full",showClear:!0,pure:!0,onChange:()=>{setTimeout(()=>{il(Xe)},0)}})}),t.jsxs("div",{className:"flex gap-2 w-full lg:w-auto",children:[t.jsx(T,{size:"small",type:"tertiary",htmlType:"submit",loading:ue||Ce,className:"flex-1 lg:flex-none",children:s("查询")}),t.jsx(T,{size:"small",type:"tertiary",onClick:()=>{Yt&&(Yt.reset(),setTimeout(()=>{tl()},100))},className:"flex-1 lg:flex-none",children:s("重置")})]})]})})]})]}),shadows:"always",bordered:!1,children:t.jsx(we,{swipeRevealRender:c?e=>{const l=P(e);if(!l)return null;const a=3===e.status?"hsl(var(--warning))":"hsl(var(--destructive))";return t.jsxs("div",{style:{width:"100%",padding:"0 6px",textAlign:"center",cursor:"pointer"},onClick:e=>{e.stopPropagation(),D(l,a)},children:[t.jsx("div",{style:{fontSize:"10px",color:"hsl(var(--muted-foreground))",marginBottom:2},children:s("禁用原因")}),t.jsx("div",{style:{fontSize:"11px",color:a,lineHeight:1.3,wordBreak:"break-word"},children:l.reason}),(l.operator||l.timeStr)&&t.jsxs("div",{style:{fontSize:"10px",color:"hsl(var(--muted-foreground))",marginTop:4,lineHeight:1.3}
1,children:[l.operator&&t.jsx("div",{children:l.operator}),l.timeStr&&t.jsx("div",{children:l.timeStr})]}),t.jsx("div",{style:{fontSize:"10px",color:"hsl(var(--primary))",marginTop:4},children:s("点击查看")})]})}:void 0,swipeColumnKeys:c?[V.OPERATE]:void 0,swipeRevealWidth:140,swipeColumnWidth:180,columns:Xt?Zs().map(({fixed:e,...t})=>t):Zs(),dataSource:hl,scroll:Xt?void 0:{x:"max-content"},pagination:{currentPage:ge,pageSize:ze,total:Ie,pageSizeOpts:[10,20,50,100],showSizeChanger:!0,formatPageText:e=>s("第 {{start}} - {{end}} 条,共 {{total}} 条",{start:e.currentStart,end:e.currentEnd,total:Ie}),onPageSizeChange:e=>{(async e=>{localStorage.setItem("page-size",e+""),Te(e),be(1),h.current=!0;const{searchKeyword:t,searchGroup:s,searchModel:l}=al();try{""===t&&""===s&&""===l?await Qs(1,e,ke,Xe):await il(Xe,Kt,re,1,e,ke)}catch(a){r(a)}finally{h.current=!1}})(e)},onPageChange:e=>{if(h.current)return;const{searchKeyword:t,searchGroup:s,searchModel:l}=al();be(e),""===t&&""===s&&""===l?Qs(e,ze,ke,Xe).then(()=>{}):il(Xe,Kt,re,e,ze,ke)}},expandAllRows:!1,onRow:(e,t)=>{let s={};return 1!==e.status&&(s={background:"hsl(var(--border))"}),{style:s}},rowSelection:Me?{onChange:(e,t)=>
1{Ze(t)}}:null,empty:t.jsx(E,{image:t.jsx(H,{style:{width:150,height:150}}),darkModeImage:t.jsx(U,{style:{width:150,height:150}}),description:s("搜索无结果"),style:{padding:30}}),className:"rounded-xl overflow-hidden",size:"middle",loading:ue||Ce})}),t.jsxs(N,{title:s("批量测试渠道"),visible:Ts,onOk:()=>{const e=Os.trim();e?(Rs(""),ul(e)):Rs(s("请输入要测试的模型名称"))},onCancel:()=>{Is(!1),Rs("")},okText:s("开始测试"),cancelText:s("取消"),maskClosable:!1,centered:!0,size:c?"full-width":"small",children:[t.jsx("div",{className:"mb-2",children:t.jsxs(w.Text,{children:[s("请输入要测试的模型名称"),t.jsx(w.Text,{type:"danger",children:" *"})]})}),t.jsx(G,{placeholder:s(c?"例如:gpt-4o、gemini-2.0-flash":"例如:gpt-4o、gemini-2.0-flash、gemini-3.1-flash-image-preview"),value:Os,onChange:e=>{As(e),e.trim()&&Rs("")},validateStatus:Es?"error":void 0,showClear:!0,autoFocus:!0,onEnterPress:()=>{const e=Os.trim();e?(Rs(""),ul(e)):Rs(s("请输入要测试的模型名称"))}}),Es&&t.jsx(w.Text,{type:"danger",size:"small",style:{marginTop:4,display:"block"},children:Es}),t.jsx("div",{className:"mt-3",children:t.jsx(w.Text,{type:"secondary",size:"small",children:s("channels_table_hint_001")})})]}),t.jsxs(N,{title:s("批量设置标签"),visible:lt,onOk:async()=>{if(0===Ye.length)return void r(s("请先选择要设置标签的渠道!"));if(""===it)return void r(s("标签不能为空!"));let e=Ye.map(e=>e.id);const t=await i.post("/api/channel/batch/tag",{ids:e,tag:""===it?null:it});t.data.success?(o(s("已为 {{num}} 个渠道设置标签!",{num:t.data.data})),await tl(),at(!1)):r(t.data.message)},onCancel:()=>at(!1),maskClosable:!1,centered:!0,size:"small",className:"!rounded-lg",children:[t.jsx("div",{className:"mb-5",children:t.jsx(w.Text,{children:s("请输入要设置的标签名称")})}),t.jsx(G,{placeholder:s("请输入标签名称"),value:it,onChange:e=>rt(e)}),t.jsx("div",{className:"mt-4",children:t.jsx(w.Text,{type:"secondary",children:s("已选择 {{num}} 个渠道",{num:Ye.length})})})]}),t.jsxs(N,{title:s("批量追加模型"),visible:nt,onOk:async()=>{if(""===ct.trim()||""===ht.trim())return void r(s("参考模型和目标模型不能为空!"));const e=await i.post("/api/channel/batch/add_model",{source_model:ct.trim(),target_model:ht.trim()});e.data.success?(o(s("已为 {{num}} 个渠道追加模型!",{num:e.data.data})),await tl(),ot(!1),dt(""),mt("")):r(e.data.message)},onCancel:()=>{ot(!1),dt(""),mt("")},maskClosable:!1,centered:!0,size:"small",className:"!rounded-lg",children:[t.jsx("div",{className:"mb-3",children:t.jsx(w.Text,{children:s("参考模型(含此模型的渠道将被更新)")})}),t.jsx(G,{placeholder:s("例如:claude-opus-4-6"),value:ct,onChange:e=>dt(e),className:"mb-4"}),t.jsx("div",{className:"mb-3",children:t.jsx(w.Text,{children:s("目标模型(追加到这些渠道中)")})}),t.jsx(G,{placeholder:s("例如:claude-sonnet-4-6"),value:ht,onChange:e=>mt(e)}),t.jsx("div",{className:"mt-4",children:t.jsx(w.Text,{type:"secondary",children:s("系统将自动查找所有包含参考模型的渠道,并将目标模型追加到其模型列表中。已包含目标模型的渠道将被跳过。")})})]}),t.jsxs(N,{title:s("批量移除模型"),visible:pt,onOk:async()=>{if(""===xt.trim())return void r(s("目标模型不能为空!"));const e=await i.post("/api/channel/batch/remove_model",{target_model:xt.trim()});e.data.success?(o(s("已从 {{num}} 个渠道移除模型!",{num:e.data.data})),await tl(),ut(!1),gt("")):r(e.data.message)},onCancel:()=>{ut(!1),gt("")},maskClosable:!1,centered:!0,size:"small",className:"!rounded-lg",children:[t.jsx("div",{className:"mb-3",children:t.jsx(w.Text,{children:s("目标模型(将从所有包含此模型的渠道中移除)")})}),t.jsx(G,{placeholder:s("例如:claude-opus-4-6"),value:xt,onChange:e=>gt(e)}),t.jsx("div",{className:"mt-4",children:t.jsx(w.Text,{type:"secondary",children:s("系统将自动查找所有包含该模型的渠道,并将其从模型列表中移除。")})})]}),t.jsx(N,{title:ft&&t.jsxs("div",{className:"flex flex-col gap-2 w-full",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs(w.Text,{strong:!0,className:"!text-[hsl(var(--foreground))] !text-base",children:[ft.name," ",s("渠道的模型测试")]}),t.jsx(w.Text,{type:"tertiary",className:"!text-xs flex items-center",children:s("共 {{num}} 个模型",{num:ft.models.split(",").length})})]}),t.jsxs("div",{className:"flex items-center justify-end gap-2 w-full",children:[t.jsx(G,{placeholder:s("搜索模型..."),value:vt,onChange:e=>{bt(e),Vt(1)},className:"!w-full",prefix:t.jsx(fe,{size:16}),showClear:!0}),t.jsx(T,{theme:"light",onClick:()=>{0!==Bt.length?d(Bt.join(",")).then(e=>{e?o(s("已复制 {{num}} 个模型",{num:Bt.length})):r(s("复制失败,请手动复制"))}
1):r(s("请先选择模型")+"!")},children:s("复制已选")}),t.jsx(T,{theme:"light",type:"primary",onClick:()=>{if(!ft)return;const e=ft.models.split(",").filter(e=>e.toLowerCase().includes(vt.toLowerCase())).filter(e=>{const t=Ot[`${ft.id}-${e}`];return t&&t.success});0===e.length&&n(s("暂无成功模型")),$t(e)},children:s("选择成功")})]}),t.jsxs("div",{className:"flex items-center gap-3 w-full flex-wrap",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(w.Text,{type:"tertiary",className:"!text-xs whitespace-nowrap",children:s("测试端点类型")}),t.jsx(C,{value:wt,onChange:e=>{kt(e),["embedding","image-generation","jina-rerank"].includes(e)&&Ct(!1)},style:{width:180},size:"small",optionList:[{value:"",label:s("自动检测")},{value:"openai",label:s("对话 (Chat)")},{value:"openai-response",label:s("Responses")},{value:"embedding",label:s("Embedding")},{value:"image-generation",label:s("图片生成")},{value:"jina-rerank",label:s("Rerank")}]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(w.Text,{type:"tertiary",className:"!text-xs whitespace-nowrap",children:s("流式")}),t.jsx(Y,{checked:St,onChange:e=>Ct(e),size:"small",disabled:["embedding","image-generation","jina-rerank"].includes(wt)})]})]})]}),visible:yt&&null!==ft,onCancel:ol,footer:t.jsxs("div",{className:"flex justify-end",children:[Mt?t.jsx(T,{type:"danger",onClick:ol,children:s("停止测试")}):t.jsx(T,{type:"tertiary",onClick:ol,children:s("取消")}),t.jsx(T,{onClick:async()=>{if(!ft)return;Lt(!0),Vt(1);const e=ft.models.split(",").filter(e=>e.toLowerCase().includes(vt.toLowerCase()));Pt(e.map((e,t)=>({channel:ft,model:e,indexInFiltered:t,endpointType:wt,stream:St}))),Dt(!0)},loading:Mt,disabled:Mt,children:Mt?s("测试中..."):s("批量测试{{num}}个模型",{num:ft?ft.models.split(",").filter(e=>e.toLowerCase().includes(vt.toLowerCase())).length:0})})]}),maskClosable:!Mt,className:"!rounded-lg",size:c?"full-width":"large",children:t.jsx("div",{className:"model-test-scroll",children:ft&&t.jsx("div",{children:t.jsx(R,{columns:[{title:s("模型名称"),dataIndex:"model",render:e=>t.jsx("div",{className:"flex items-center",children:t.jsx(w.Text,{strong:!0,children:e})})},{title:s("状态"),dataIndex:"status",render:(e,l)=>{const a=Ot[`${ft.id}-${l.model}`];return Et.has(l.model)?t.jsx(k,{color:"blue",shape:"circle",children:s("测试中...")}):a?t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(k,{color:a.success?"green":"red",shape:"circle",children:a.success?s("成功"):s("失败")}),a.success&&t.jsx(w.Text,{type:"tertiary",children:s("请求时长: {{time}}s",{time:a.time.toFixed(2)})})]}):t.jsx(k,{color:"grey",shape:"circle",children:s("未开始")})}},{title:"",dataIndex:"operate",render:(e,l)=>{const a=Et.has(l.model);return t.jsx(T,{type:"tertiary",onClick:()=>nl(ft,l.model,wt,St),loading:a,size:"small",children:s("测试")})}}],dataSource:(()=>{const e=ft.models.split(",").filter(e=>e.toLowerCase().includes(vt.toLowerCase())),t=(Ft-1)*b,s=t+b;return e.slice(t,s).map(e=>({model:e,key:e}))})(),rowSelection:{selectedRowKeys:Bt,onChange:e=>{vs.current?vs.current=!1:$t(e)},onSelectAll:e=>{const t=ft.models.split(",").filter(e=>e.toLowerCase().includes(vt.toLowerCase()));vs.current=!0,$t(e?t:[])}},pagination:{currentPage:Ft,pageSize:b,total:ft.models.split(",").filter(e=>e.toLowerCase().includes(vt.toLowerCase())).length,showSizeChanger:!1,onPageChange:e=>Vt(e)}})})})}),t.jsx(tt,{visible:Nt,onCancel:()=>{zt(!1),It(null)},channelId:Tt?.id,channelName:Tt?.name}),t.jsx(N,{title:s("修改成本核算"),visible:rs,onOk:async()=>{if(!os)return;const e=await i.put("/api/channel/",{id:os.id,recharge_price:ds.recharge_price,group_ratio:ds.group_ratio}),{success:t,message:l}=e.data;t?(o(s("操作成功完成!")),ns(!1),cs(null),await tl()):r(l)},onCancel:()=>{ns(!1),cs(null)},okText:s("保存"),cancelText:s("取消"),centered:!0,children:t.jsxs("div",{style:{padding:"8px 0"},children:[t.jsxs("div",{style:{marginBottom:16},children:[t.jsx("div",{style:{marginBottom:6,fontWeight:500},children:s("充值汇率")}
1),t.jsx("div",{style:{marginBottom:4,color:"hsl(var(--muted-foreground))",fontSize:12},children:s("1 表示 1人民币=1额度,默认为1")}),t.jsx(I,{style:{width:"100%"},value:ds.recharge_price,onChange:e=>hs(t=>({...t,recharge_price:e})),placeholder:s("默认为1"),min:0,step:.01,precision:4})]}),t.jsxs("div",{children:[t.jsx("div",{style:{marginBottom:6,fontWeight:500},children:s("分组倍率")}),t.jsx("div",{style:{marginBottom:4,color:"hsl(var(--muted-foreground))",fontSize:12},children:s("实际成本 = 充值汇率 × 分组倍率,默认为1")}),t.jsx(I,{style:{width:"100%"},value:ds.group_ratio,onChange:e=>hs(t=>({...t,group_ratio:e})),placeholder:s("默认为1"),min:0,step:.01,precision:4})]})]})}),t.jsxs(N,{title:s("禁用渠道"),visible:es,onOk:async()=>{if(!as)return;if(!ss.trim())return void r(s("请填写禁用原因"));const{id:e,record:t}=as,l=await i.put("/api/channel/",{id:e,status:2,disable_reason:ss.trim()}),{success:a,message:n}=l.data;if(a){o(s("操作成功完成!"));let e=[...me];t.status=2,pe(e)}else r(n);ts(!1),ls(""),is(null)},onCancel:()=>{ts(!1),ls(""),is(null)},okText:s("确认禁用"),cancelText:s("取消"),okButtonProps:{type:"danger"},centered:!0,children:[t.jsxs("div",{style:{marginBottom:8},children:[t.jsx("span",{style:{color:"hsl(var(--destructive))",marginRight:4},children:"*"}),s("请填写禁用原因(必填)")]}),t.jsx(Z,{value:ss,onChange:e=>ls(e),placeholder:s("例如:价格异常、账号欠费、上游故障..."),rows:4,maxCount:200,showClear:!0})]}),t.jsxs(B,{title:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(w.Title,{heading:5,style:{margin:0},children:s("渠道测试记录")}),bs&&Cs&&t.jsx(k,{color:"orange",size:"small",children:s("测试中 {{done}}/{{total}}",{done:Cs.finished,total:Cs.total})})]}),visible:Bs,onCancel:()=>$s(!1),placement:c?"bottom":"right",width:c?"100%":680,height:c?"85vh":void 0,style:c?{}:{maxWidth:"95vw"},bodyStyle:{padding:0,overflowY:"auto",overscrollBehavior:"contain",WebkitOverflowScrolling:"touch"},headerStyle:{borderBottom:"1px solid hsl(var(--border))"},children:[bs&&Cs&&t.jsxs("div",{style:{position:"sticky",top:0,zIndex:10,background:"hsl(var(--background))",borderBottom:"1px solid hsl(var(--border))",padding:"12px 16px"},children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsx(w.Text,{strong:!0,children:s("批量测试进行中...")}),t.jsx(w.Text,{type:"tertiary",size:"small",children:s("成功 {{s}} | 失败 {{f}} | 共 {{t}} 个",{s:Cs.succeeded,f:Cs.failed,t:Cs.total})})]}),t.jsx(X,{percent:Math.round(Cs.finished/Cs.total*100),showInfo:!0,size:"default",stroke:Cs.failed>0?"hsl(var(--warning))":"hsl(var(--success))"}),Cs.results&&Cs.results.length>0&&t.jsx("div",{className:"mt-3",style:{maxHeight:c?"28vh":"200px",overflowY:"auto",overscrollBehavior:"contain"},children:[...Cs.results].reverse().slice(0,10).map((e,t)=>_l(e,t,!0))})]}),t.jsxs("div",{style:{padding:"16px"},children:[t.jsxs("div",{className:"flex items-center justify-between mb-3",children:[t.jsx(w.Text,{strong:!0,children:s("历史记录")}),t.jsx(T,{size:"small",type:"tertiary",loading:Fs,onClick:gl,children:s("刷新")})]}),Fs&&0===Ws.length?t.jsx("div",{className:"flex justify-center py-8",children:t.jsx(A,{})}):0===Ws.length?t.jsx(E,{image:t.jsx(H,{style:{width:80,height:80}}),darkModeImage:t.jsx(U,{style:{width:80,height:80}}),description:s("暂无测试记录"),style:{padding:24}}):t.jsx("div",{className:"flex flex-col gap-2",children:Ws.map(e=>{const l=Ks===e.task_id,a=bs&&ks===e.task_id,r=new Date(1e3*e.created_at).toLocaleString("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"});return t.jsxs(L,{shadows:"hover",bordered:!0,style:{borderRadius:8},bodyStyle:{padding:"12px 16px"},children:[t.jsxs("div",{className:"flex items-center justify-between cursor-pointer",onClick:()=>a?null:(async e=>{if(Ks===e)return qs(null),void Hs(null);qs(e),Ys(!0);try{const t=await i.get(`/api/channel/batch_test/${e}`),{success:s,data:l}=t.data;s&&Hs(l)}catch(t){}finally{Ys(!1)}})(e.task_id),children:[t.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.jsx(k,{color:"done"===e.status?e.failed>0?"orange":"green":"blue",size:"small",children:"done"===e.status?s("完成"):s("进行中")}),t.jsx(w.Text,{size:"small",type:"secondary",children:r}),t.jsx(w.Text,{size:"small",children:s("共{{total}}项",{total:e.total})})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsxs(w.Text,{size:"small",style:{color:"hsl(var(--success))"},children:["✓ ",e.succeeded]}),t.jsxs(w.Text,{size:"small",style:{color:"hsl(var(--destructive))"},children:["✗ ",e.failed]}),!a&&t.jsx(w.Text,{size:"small",type:"tertiary",children:l?"▲":"▼"})]})]}),"done"!==e.status&&t.jsx("div",{className:"mt-2",children:t.jsx(X,{percent:Math.round(e.finished/e.total*100),showInfo:!0,size:"small"})}),l&&!a&&t.jsx("div",{className:"mt-3",children:Gs?t.jsx("div",{className:"flex justify-center py-4",children:t.jsx(A,{})}):Us&&Us.results?t.jsx("div",{children:Us.results.map((e,t)=>_l(e,t,!0))}):null}),a&&Cs&&Cs.results&&t.jsxs("div",{className:"mt-3",children:[t.jsx(X,{percent:Math.round(Cs.finished/Cs.total*100),showInfo:!0,size:"small",className:"mb-2"}),[...Cs.results].reverse().slice(0,5).map((e,t)=>_l(e,t,!1))]})]},e.task_id)})})]})]}),t.jsx(N,{title:s("失败原因"),visible:!!Js,onCancel:()=>Ps(null),footer:t.jsx(T,{type:"primary",onClick:()=>Ps(null),children:s("关闭")}),centered:!0,size:c?"full-width":"small",children:Js&&t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.jsx(w.Text,{strong:!0,children:Js.channel_name}),t.jsxs(w.Text,{type:"secondary",children:["#",Js.channel_id]}),t.jsx(k,{size:"small",color:"blue",children:Js.model})]}),t.jsx("div",{style:{background:"hsl(var(--foreground) / 0.02)",borderRadius:6,padding:"10px 12px",wordBreak:"break-all",fontSize:13,lineHeight:1.6,color:"hsl(var(--destructive))",maxHeight:"50vh",overflowY:"auto"},children:Js.message||s("无错误信息")})]})})]})},lt=()=>t.jsx("div",{className:"px-2",children:t.jsx(st,{})});
1export{lt as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.