PageSourceSearch

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

js nickz.ai collected 2026-10-05 14:20:07 UTC 57,806 bytes, 1 lines download raw bytes

1import{r as e,j as s}from"./vendor-react-DejgYtBM.js";import{u as t,S as a,a as r,v as l,w as i,aH as n,A as o,O as c,s as d,Y as m,aI as u,W as p,K as h,N as x,aj as g,Z as j,ag as y}from"./index-BeIIFw6E.js";import{M as f,j as v,f as b,B as w,W as _,l as k,o as N,m as C,A as S,R as $,C as z,v as I,aq as T,i as q,u as A,r as O,z as P,ar as W,as as B,k as L,at as R,au as M,av as V,aw as E,ax as H,ay as D,az as F,aA as K,aB as U,aC as G,P as J,F as Y,aD as X,E as Z,J as Q,K as ee}from"./vendor-semi-D8d7bTtM.js";import{g as se}from"./cherryStudioUtils-BalcJ1dl.js";import{k as te,E as ae,V as re,C as le,K as ie,Z as ne,t as oe,u as ce,bm as de,bB as me,ba as ue,I as pe,q as he,at as xe,bt as ge,j as je,bC as ye,d as fe,e as ve,X as be}from"./vendor-icons-EJvJ5X-w.js";import{u as we}from"./useTableCompactMode-DWLN7NUj.js";import{C as _e}from"./CardTable-Cq0lqlnD.js";import{C as ke}from"./CardPro-DfDWu9ok.js";import{u as Ne}from"./useIsMobile-D_kfVI0u.js";import"./vendor-motion-Chfy_MiU.js";const{Text:Ce}=b;function Se(e){return String(e||"").replace(/\/$/,"")}function $e(e){if(!e)return!1;const s=String(e).toLowerCase();return"localhost"===s||"127.0.0.1"===s||"[::1]"===s||s.endsWith(".localhost")}function ze(){if("undefined"==typeof localStorage)return null;try{const e=localStorage.getItem("status");return e?JSON.parse(e):null}catch(e){return null}}function Ie(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function Te(e){return e.replace(/'/g,"'\\''")}function qe({visible:n,onClose:o,keys:c=[],groups:d=[]}){const{t:m}=t(),[u]=e.useContext(a),[p,h]=e.useState("openai"),[x,g]=e.useState("python"),[j,y]=e.useState(!1),b=r(),_=e.useMemo(()=>function(e){let s=e&&e.server_address||("undefined"!=typeof localStorage?localStorage.getItem("server_address"):"")||"";if(!s&&"undefined"!=typeof localStorage){const e=ze();e&&"object"==typeof e&&(s=e.server_address||"")}if("undefined"==typeof window)return Se(s)||"";const t=window.location.origin;if(!$e(window.location.hostname))return Se(t);if(s){const e=Se(String(s).trim());try{if(!$e(new URL(e).hostname))return e}catch(a){}}return Se(t)}(u?.status),[u?.status?.server_address,n]),k=u?.status?.system_name||ze()?.system_name||"API",N=_||function(){const e=("undefined"!=typeof window?window.location.origin:"")||"";return String(e).replace(/\/$/,"")}(),C=`${N}/v1`,S=`${N}/v1`,$=`${N}/v1beta`,z=c[0]||"",I=z.startsWith("sk-")?z.slice(3):z,T=z.length>12?`${z.slice(0,7)}${"*".repeat(Math.min(16,z.length-12))}${z.slice(-4)}`:z,q="openai"===p?C:N,A=e.useMemo(()=>function(e,s,t,a){const r="gpt-5.5-pro",l="claude-opus-4-7",i="gemini-3.1-pro-preview",n=t.replace("/v1",""),o="你好,请用一句话介绍你自己。",c=JSON.stringify({model:r,messages:[{role:"user",content:o}],temperature:.7}),d=JSON.stringify({model:l,max_tokens:1024,messages:[{role:"user",content:o}]}),m=JSON.stringify({contents:[{role:"user",parts:[{text:o}]}]}),u=["# Windows(CMD / PowerShell):请用 curl.exe,单行粘贴;不要用 bash 的 \\ 续行",`curl.exe -sS "${s}/chat/completions" -H "Authorization: Bearer ${e}" -H "Content-Type: application/json" -d "${Ie(c)}"`,"","# Linux / macOS / Git Bash:",`curl -sS "${s}/chat/completions" \\`,`  -H "Authorization: Bearer ${e}" \\`,'  -H "Content-Type: application/json" \\',`  -d '${Te(c)}'`].join("\n");return{openai:{python:`# POST ${s}/chat/completions(OpenAI 兼容)\nfrom openai import OpenAI\n\nclient = OpenAI(api_key="${e}", base_url="${s}")\n\nresp = client.chat.completions.create(\n    model="${r}",\n    messages=[{"role": "user", "content": "${o}"}],\n    temperature=0.7,\n)\nprint(resp.choices[0].message.content)`,node:`// POST ${s}/chat/completions\nimport OpenAI from "openai";\n\nconst client = new OpenAI({ apiKey: "${e}", baseURL: "${s}" });\n\nconst resp = await client.chat.completions.create({\n  model: "${r}",\n  messages: [{ role: "user", content: "${o}" }],\n  temperature: 0.7,\n});\nconsole.log(resp.choices[0]?.message?.content);`,curl:u},anthropic:{python:`# POST ${t}/messages(Claude Messages;令牌也可用 Authorization: Bearer)\nfrom anthropic import Anthropic\n\nclient = Anthropic(api_key="${e}", base_url="${n}")\n\nmsg = client.messages.create(\n    model="${l}",\n    max_tokens=1024,\n    messages=[{"role": "user", "content": "${o}"}],\n)\nprint(msg.content[0].text)`,node:`// POST ${t}/messages\nimport Anthropic from "@anthropic-ai/sdk";\n\nconst client = new Anthropic({ apiKey: "${e}", baseURL: "${n}" });\n\nconst msg = await client.messages.create({\n  model: "${l}",\n  max_tokens: 1024,\n  messages: [{ role: "user", content: "${o}" }],\n});\nconsole.log(msg.content[0]?.text);`,curl:["# Windows(CMD / PowerShell)",`curl.exe -sS "${t}/messages" -H "x-api-key: ${e}" -H "anthropic-version: 2023-06-01" -H "Content-Type: application/json" -d "${Ie(d)}"`,"","# Linux / macOS / Git Bash:",`curl -sS "${t}/messages" \\`,`  -H "x-api-key: ${e}" \\`,'  -H "anthropic-version: 2023-06-01" \\','  -H "Content-Type: application/json" \\',`  -d '${Te(d)}'`].join("\n")},gemini:{python:`# POST ${a}/models/${i}:generateContent(也可用 Authorization Bearer 或 URL ?key=)\nimport requests\n\nurl = "${a}/models/${i}:generateContent"\nheaders = {"x-goog-api-key": "${e}", "Content-Type": "application/json"}\nbody = {"contents": [{"role": "user", "parts": [{"text": "${o}"}]}]}\nr = requests.post(url, headers=headers, json=body, timeout=120)\nprint(r.json())`,node:`// POST ${a}/models/${i}:generateContent\nconst apiKey = "${e}";\nconst url = "${a}/models/${i}:generateContent";\nconst res = await fetch(url, {\n  method: "POST",\n  headers: {\n    "x-goog-api-key": apiKey,\n    "Content-Type": "application/json",\n  },\n  body: JSON.stringify({\n    contents: [{ role: "user", parts: [{ text: "${o}" }] }],\n  }),\n});\nconsole.log(await res.json());`,curl:["# Windows(CMD / PowerShell)",`curl.exe -sS "${a}/models/${i}:generateContent" -H "x-goog-api-key: ${e}" -H "Content-Type: application/json" -d "${Ie(m)}"`,"","# Linux / macOS / Git Bash:",`curl -sS "${a}/models/${i}:generateContent" \\`,`  -H "x-goog-api-key: ${e}" \\`,'  -H "Content-Type: application/json" \\',`  -d '${Te(m)}'`].join("\n")},cherry:{python:`# Cherry Studio:添加供应商 → 选「OpenAI」或「OpenAI 兼容」\n#   API 地址(Base URL):${s}\n#   API 密钥:${e}\n# 亦可使用应用内「导入」功能,粘贴 Base64(见弹窗内「复制 Cherry 导入」按钮)\n#\n# 以下为与本站 OpenAI 兼容接口相同的命令行验证:\nfrom openai import OpenAI\n\nclient = OpenAI(api_key="${e}", base_url="${s}
1")\n\nresp = client.chat.completions.create(\n    model="${r}",\n    messages=[{"role": "user", "content": "${o}"}],\n    temperature=0.7,\n)\nprint(resp.choices[0].message.content)`,node:`// Cherry Studio:Base URL = ${s},API Key = 上方令牌\n// 导入 Base64 可用下方「复制 Cherry 导入」\n//\n// 验证请求(POST ${s}/chat/completions)\nimport OpenAI from "openai";\n\nconst client = new OpenAI({ apiKey: "${e}", baseURL: "${s}" });\n\nconst resp = await client.chat.completions.create({\n  model: "${r}",\n  messages: [{ role: "user", content: "${o}" }],\n  temperature: 0.7,\n});\nconsole.log(resp.choices[0]?.message?.content);`,curl:["# Cherry Studio 填写的 Base URL 末级一般为 /v1,请求路径仍为 chat/completions","# 验证请求(与 OpenAI 兼容 chat/completions 相同):","",...u.split("\n")].join("\n")}}}(z,C,S,$),[z,C,S,$]),O=A[p]?.[x]||A.openai.python,P=async e=>{await l(e)&&i(m("已复制到剪贴板")+"!")};return e.useMemo(()=>{if(!I)return"";try{return se("anthropic"===p?"anthropic":"gemini"===p?"gemini":"openai",I,N,k,d)}catch{return""}},[I,N,p,k,d]),e.useMemo(()=>{try{const e=localStorage.getItem("chats");if(!e)return[];const s=JSON.parse(e);return Array.isArray(s)?s.map((e,s)=>{const t=Object.keys(e)[0];return{key:`chat-${s}`,label:t,urlTemplate:e[t]}}).filter(e=>e.label&&e.urlTemplate):[]}catch{return[]}},[n]),s.jsx(f,{title:null,visible:n,onCancel:o,footer:null,size:b?"full-width":void 0,width:b?void 0:560,maskClosable:!1,closeOnEsc:!0,bodyStyle:{maxWidth:"100%",overflowX:"hidden",overflowY:"auto",maxHeight:"calc(90vh - 48px)",boxSizing:"border-box"},children:s.jsxs("div",{style:{padding:"4px 0 8px",maxWidth:"100%",minWidth:0,boxSizing:"border-box"},children:[s.jsx("div",{className:"flex items-start justify-between gap-3",children:s.jsxs(v,{spacing:10,align:"start",children:[s.jsx(te,{size:22,className:"text-green-600 flex-shrink-0 mt-0.5",strokeWidth:2.4}),s.jsxs("div",{children:[s.jsx(Ce,{strong:!0,style:{fontSize:b?15:17},children:m("API Key 已创建")}),s.jsx("div",{style:{marginTop:6,color:"hsl(var(--muted-foreground))",fontSize:b?12:13},children:m("请立即复制保存,后续可在令牌列表再次查看,请勿泄露给他人")})]})]})}),s.jsxs("div",{style:{marginTop:14,display:"flex",alignItems:"center",gap:8,padding:"10px 12px",borderRadius:8,background:"hsl(var(--foreground) / 0.02)",border:"1px solid hsl(var(--border))",minWidth:0,maxWidth:"100%"},children:[s.jsx("span",{style:{flex:1,minWidth:0,fontFamily:"ui-monospace, monospace",fontSize:13,wordBreak:"break-all",overflowWrap:"anywhere"}
1,children:j?z:T}),s.jsx(w,{type:"tertiary",theme:"borderless",icon:j?s.jsx(ae,{size:16}):s.jsx(re,{size:16}),onClick:()=>y(!j),"aria-label":m("显示/隐藏")}),s.jsx(w,{type:"tertiary",theme:"borderless",icon:s.jsx(le,{size:16}),onClick:()=>P(c.length>1?c.join("\n"):z)})]}),c.length>1&&s.jsx(Ce,{type:"tertiary",size:"small",style:{display:"block",marginTop:8},children:m("本次共创建 {{count}} 个令牌,点击复制将包含全部密钥(每行一个)",{count:c.length})}),s.jsxs("div",{style:{marginTop:22},children:[s.jsx(Ce,{strong:!0,style:{fontSize:b?14:15},children:m("快速接入")}),s.jsx("div",{className:"flex flex-wrap gap-2 mt-3",children:[{id:"openai",name:"OpenAI"},{id:"anthropic",name:"Anthropic"},{id:"gemini",name:"Gemini"}].map(e=>s.jsx(w,{size:"small",type:p===e.id?"primary":"tertiary",theme:p===e.id?"solid":"light",onClick:()=>h(e.id),children:e.name},e.id))}),s.jsxs("div",{style:{marginTop:12,padding:"10px 12px",borderRadius:8,background:"hsl(var(--foreground) / 0.02)",border:"1px solid hsl(var(--border))",display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:8,minWidth:0,maxWidth:"100%"},children:[s.jsxs("div",{style:{flex:1,minWidth:0},children:[s.jsxs(Ce,{size:"small",style:{wordBreak:"break-all",overflowWrap:"anywhere"},children:["Base URL:",q]}),"openai"!==p?s.jsx(Ce,{type:"tertiary",size:"small",style:{display:"block",marginTop:4}}):null]}),s.jsx(w,{type:"tertiary",size:"small",icon:s.jsx(le,{size:16}),style:{flexShrink:0},onClick:()=>P(q),children:m("复制")})]}),s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"flex flex-wrap gap-2 mt-3",children:[{id:"python",name:"Python"},{id:"node",name:"Node.js"},{id:"curl",name:"cURL"}].map(e=>s.jsx(w,{size:"small",type:x===e.id?"primary":"tertiary",theme:x===e.id?"solid":"light",onClick:()=>g(e.id),children:e.name},e.id))}),s.jsxs("div",{style:{position:"relative",marginTop:10,width:"100%",minWidth:0,maxWidth:"100%"},children:[s.jsx(w,{type:"tertiary",theme:"borderless",icon:s.jsx(le,{size:16}),style:{position:"absolute",right:8,top:8,zIndex:1},onClick:()=>P(O)}),s.jsx("pre",{style:{margin:0,padding:b?"32px 10px 12px":"36px 12px 14px",borderRadius:10,background:"#1e1e1e",color:"#d4d4d4",fontSize:b?11:12,lineHeight:1.55,overflow:"auto",overflowX:"auto",maxHeight:b?220:360,maxWidth:"100%",whiteSpace:"pre-wrap",wordBreak:"break-all",overflowWrap:"anywhere",boxSizing:"border-box"},children:s.jsx("code",{style:{display:"block",whiteSpace:"pre-wrap",wordBreak:"break-all",overflowWrap:"anywhere"},children:O})})]})]})]}),!1,s.jsx("div",{className:"flex justify-end mt-6",children:s.jsx(w,{type:"primary",theme:"solid",onClick:o,children:m("知道了")})})]})})}const{Text:Ae,Title:Oe}=b,Pe=e=>e<=1?"green":e<=3?"blue":e<=7?"orange":"red",We=e=>[{label:e("智能自动"),value:"auto",extra:e("综合价格、速度、成功率自动选择"),detail:e("在已选分组的可用渠道内,综合价格、速度、成功率等近期数据自动排序;不是旧版 auto 分组。"),icon:ne,accent:"hsl(217 91% 60%)",bg:"hsl(217 91% 60% / 0.1)"},{label:e("价格优先"),value:"price",extra:e("优先选择成本更低的渠道"),detail:e("在可用渠道内优先选择成本更低的渠道,适合预算敏感场景。"),icon:xe,accent:"hsl(142 71% 36%)",bg:"hsl(142 71% 36% / 0.1)"},{label:e("速度优先"),value:"speed",extra:e("优先选择响应更快的渠道"),detail:e("在可用渠道内优先选择响应更快的渠道,适合对延迟敏感的请求。"),icon:ge,accent:"hsl(32 95% 44%)",bg:"hsl(32 95% 44% / 0.1)"},{label:e("成功率优先"),value:"success_rate",extra:e("优先选择近期更稳定的渠道"),detail:e("在可用渠道内优先选择近期成功率更高的渠道,适合稳定性优先场景。"),icon:je,accent:"hsl(345 83% 50%)",bg:"hsl(345 83% 50% / 0.1)"}],Be=({value:e,onChange:t,disabled:a,t:r})=>s.jsxs("div",{className:"space-y-2.5",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[s.jsxs("div",{className:"text-sm font-medium flex-shrink-0",style:{color:"var(--semi-color-text-0)"},children:[r("智能路由")," ",s.jsx("span",{style:{color:"var(--semi-color-danger)"},children:"*"})]}),s.jsx(Ae,{type:"tertiary",className:"text-xs flex-shrink-0",children:r("请求级可覆盖")})]}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[s.jsx(Ae,{type:"tertiary",className:"text-xs whitespace-nowrap",children:r(e?"智能路由已开启":"已关闭")}),s.jsx(O,{checked:!!e,disabled:a,onChange:e=>t(e?"auto":""),"aria-label":r("智能路由"),size:"small",style:{backgroundColor:e?"hsl(217 91% 60%)":"rgba(0,0,0,0.75)"}})]})]}),s.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:We(r).map(r=>{const l=r.icon,i=(e??"auto")===r.value;return s.jsx("button",{type:"button",disabled:a,"aria-pressed":i,onClick:()=>t(r.value),className:"w-full text-left rounded-lg px-3 py-2.5 transition-all",style:{minHeight:64,border:i?`1px solid ${r.accent}`:"1px solid var(--semi-color-border)",background:i?r.bg:"var(--semi-color-bg-0)",boxShadow:i?`0 0 0 2px ${r.bg}`:"none",cursor:a?"not-allowed":"pointer",opacity:a?.55:1},children:s.jsxs("div",{className:"flex items-center gap-2.5",children:[s.jsx("span",{className:"inline-flex items-center justify-center rounded-md flex-shrink-0",style:{width:28,height:28,color:r.accent,background:i?"var(--semi-color-bg-0)":r.bg},children:s.jsx(l,{size:15})}),s.jsxs("span",{className:"min-w-0",children:[s.jsxs("span",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"block text-sm font-medium truncate",style:{color:"var(--semi-color-text-0)"},children:r.label}),s.jsx(P,{content:r.detail,position:"top",showArrow:!0,style:{maxWidth:280},children:s.jsx(he,{size:14,className:"flex-shrink-0",style:{color:"var(--semi-color-text-2)"}})})]}),s.jsx("span",{className:"block text-xs mt-0.5 leading-snug",style:{color:"var(--semi-color-text-2)",display:"-webkit-box",WebkitLineClamp:1,WebkitBoxOrient:"vertical",overflow:"hidden"},children:r.extra})]})]})},r.value)})}),s.jsxs("div",{className:"flex items-start gap-1.5 rounded-md px-2.5 py-1.5 text-xs leading-relaxed",style:{color:"var(--semi-color-text-2)"},children:[s.jsx(pe,{size:14,className:"mt-0.5 flex-shrink-0"}),s.jsx("span",{children:r("API 请求中的模型后缀和 provider.sort 会覆盖令牌级智能路由。")})]})]}),Le=({groupValue:e,index:t,group:a,onRemove:r,t:l})=>{const{attributes:i,listeners:n,setNodeRef:o,transform:c,transition:d,isDragging:m}=U({id:e}),u={transform:G.Transform.toString(c),transition:d,opacity:m?.5:1,backgroundColor:"hsl(var(--secondary))",border:m?"1px dashed hsl(var(--primary))":"1px solid hsl(var(--border))",zIndex:m?1e3:"auto"};return s.jsxs("div",{ref:o,style:u,className:"flex items-center justify-between p-2 rounded hover:shadow-sm transition-shadow",children:[s.jsx("div",{...i,...n,className:"cursor-grab active:cursor-grabbing mr-2 p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-700",style:{touchAction:"none"},title:l("拖拽调整顺序"),children:s.jsx(ye,{size:14,style:{color:"hsl(var(--muted-foreground))"}})}),s.jsxs("div",{className:"flex items-center flex-1 min-w-0",children:[s.jsxs(q,{color:"blue",size:"small",className:"mr-2 flex-shrink-0",children:[l("优先级")," ",t+1]}),s.jsx("span",{className:"font-medium text-sm truncate",children:e}),s.jsx("span",{className:"text-xs ml-2 truncate",style:{color:"hsl(var(--muted-foreground))"},children:a?.description||""})]}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[a?.parsedInfo&&s.jsxs(q,{color:Pe(a.parsedInfo.multiplier),size:"small",children:[a.parsedInfo.multiplier,"倍"]}),s.jsx(w,{type:"tertiary",theme:"borderless",size:"small",icon:s.jsx(ue,{size:16}),onClick:r,className:"!w-6 !h-6 !p-0",style:{minWidth:"24px",color:"hsl(var(--muted-foreground))"}})]})]})},Re=({groups:e,selectedGroups:a,onGroupsChange:r})=>{const{t:l}
1=t(),i=Array.isArray(a)?a.filter(Boolean):[],n=W(B(K,{activationConstraint:{distance:8}}),B(F,{coordinateGetter:D}));return s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center justify-between mb-2",children:[s.jsx("span",{className:"font-medium",children:l("分组优先级选择")}),s.jsx(Ae,{type:"secondary",className:"text-xs",children:i.length>0?`已选择 ${i.length} 个分组`:"未选择分组"})]}),s.jsx(L,{placeholder:l("选择分组,可多选,选择顺序即为优先级顺序"),multiple:!0,value:i,onChange:e=>{r(e)},renderSelectedItem:(t,{index:a,onClose:r})=>{let l=t?.value||t?.props?.value||t;!l&&a<i.length&&(l=i[a]);const n=e.find(e=>e.value===l);return n&&n.parsedInfo?{isRenderInTag:!1,content:s.jsx(q,{closable:!0,onClose:r,color:Pe(n.parsedInfo.multiplier),size:"small",className:"!px-3 !py-1",children:s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"font-medium",children:l}),s.jsx("span",{className:"opacity-75",children:"•"}),s.jsxs("span",{className:"text-xs px-1.5 py-0.5 rounded font-mono",style:{backgroundColor:"hsl(var(--foreground) / 0.2)"},children:[n.parsedInfo.multiplier,"×"]})]})})}:{isRenderInTag:!1,content:s.jsx(q,{closable:!0,onClose:r,size:"small",className:"!px-3 !py-1",color:"grey",children:s.jsx("span",{className:"font-medium",children:l||`分组${a+1}`})})}},filter:!0,showClear:!0,maxTagCount:2,showRestTagsPopover:!0,restTagsPopoverProps:{position:"top"},expandRestTagsOnClick:!0,getPopupContainer:()=>document.body,zIndex:1100,dropdownStyle:{maxWidth:"min(100vw - 24px, 560px)",boxSizing:"border-box"},dropdownClassName:"token-group-select-dropdown",className:"w-full",onChangeWithObject:!1,children:e.map(e=>s.jsx(L.Option,{value:e.value,children:e.parsedInfo?s.jsxs("div",{className:"w-full max-w-full box-border py-2 px-3",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[s.jsx("span",{className:"text-sm font-medium",style:{color:"var(--semi-color-text-0)",wordBreak:"break-word",overflowWrap:"anywhere"},children:e.value}),s.jsx(q,{color:Pe(e.parsedInfo.multiplier),size:"small",className:"!m-0 flex-shrink-0",children:`${e.parsedInfo.multiplier}倍`})]}),(e.description||e.parsedInfo.description)&&s.jsx("div",{className:"text-xs mt-1",style:{color:"var(--semi-color-text-2)",wordBreak:"break-word",overflowWrap:"anywhere"},children:e.description||e.parsedInfo.description})]}):s.jsx("div",{className:"py-2 px-3",children:s.jsx("div",{className:"text-sm",children:e.label})})},e.value))}),s.jsxs("div",{className:"mt-2 flex items-start gap-2 rounded-lg border px-3 py-2 text-xs leading-relaxed",style:{color:"var(--semi-color-text-2)",borderColor:"var(--semi-color-border)",backgroundColor:"var(--semi-color-fill-0)"},children:[s.jsx(pe,{size:14,className:"mt-0.5 flex-shrink-0"}),s.jsx("span",{children:l("选择顺序决定分组优先级;智能路由决定渠道排序;未选择时使用账号默认分组。")})]})]}),i.length>0&&s.jsxs("div",{className:"mt-3 p-3 rounded-lg",style:{backgroundColor:"hsl(var(--foreground) / 0.02)"},children:[s.jsxs("div",{className:"flex items-center justify-between mb-3",children:[s.jsx(Ae,{strong:!0,className:"text-sm",children:l("当前优先级顺序")}),s.jsx(Ae,{type:"tertiary",className:"text-xs",children:l("拖拽调整顺序")})]}),s.jsx(R,{sensors:n,collisionDetection:M,onDragEnd:e=>{const{active:s,over:t}=e;if(s.id!==t?.id){const e=i.indexOf(s.id),a=i.indexOf(t.id),l=H(i,e,a);r(l)}},children:s.jsx(V,{items:i,strategy:E,children:s.jsx("div",{className:"space-y-2",children:i.map((t,a)=>{const n=e.find(e=>e.value===t);
1return s.jsx(Le,{groupValue:t,index:a,group:n,t:l,onRemove:()=>{const e=i.filter(e=>e!==t);r(e)}},t)})})})})]})]})},Me=a=>{const{t:l}=t(),[x,g]=e.useState(!1),j=r(),y=e.useRef(null),[b,O]=e.useState([]),[P,W]=e.useState([]),B=void 0!==a.editingToken.id,[L,R]=e.useState([]),[M,V]=e.useState([]),[E,H]=e.useState(!1),[D,F]=e.useState(0),[K,U]=e.useState(!1),[G,J]=e.useState("never"),[Y,X]=e.useState(!1),[Z,Q]=e.useState([]),[ee,se]=e.useState([]),te=a.isBatchMode||!1,[ae,re]=e.useState({routing:!1,group:!1,expiry:!1,quota:!1,modelLimits:!1,allowIps:!1,midjourney:!1}),le=()=>{H(!1),F(0),V([]),U(!1),te&&re({routing:!1,group:!1,expiry:!1,quota:!1,modelLimits:!1,allowIps:!1,midjourney:!1}),J("never"),a.handleClose()},he=(e,s,t,a)=>{let r=(new Date).getTime()/1e3,l=30*e*24*60*60;l+=24*s*60*60,l+=60*t*60,l+=60*a,y.current&&(0!==l?(r+=l,y.current.setValue("expired_time",m(r)),J(1===e&&0===s&&0===t&&0===a?"1m":0===e&&1===s&&0===t&&0===a?"1d":0===e&&0===s&&1===t&&0===a?"1h":"custom")):(y.current.setValue("expired_time",-1),J("never")))},xe=()=>{if(!y.current)return;const e=new Date,s=new Date(e.getFullYear(),e.getMonth()+1,0,23,59,59),t=Math.floor(s.getTime()/1e3);y.current.setValue("expired_time",m(t)),J("eom")},ge=async e=>{let s=await o.get("/api/user/models"+(e?`?group=${e}`:""));const{success:t,message:a,data:r}=s.data;if(t){c(l);let e=r.map(e=>({label:e,value:e}));O(e)}else d(l(a))};e.useEffect(()=>{y.current&&(B||(y.current.setValues({name:"",remain_quota:0,expired_time:-1,unlimited_quota:!0,model_limits_enabled:!1,model_limits:[],allow_ips:"",group:"",routing_priority:"auto",tokenCount:1,mj_image_mode:"default",mj_custom_proxy:"",selected_groups:[]}),J("never"))),ge(),(async()=>{let e=await o.get("/api/user/self/groups");const{success:s,message:t,data:a}=e.data;if(s){let e;if(a&&a.data&&a.ratios){const{data:s,ratios:t}=a;e=Object.keys(s).map(e=>({label:`${e} ${s[e]}`,value:e,description:s[e],parsedInfo:{tag:e,description:s[e],multiplier:t[e]||1}}))}else{if(!a||"object"!=typeof a)return console.error("🎯 二开功能:未知的API响应格式",a),void d(l("分组数据格式错误"));e=Object.entries(a).map(([e,s])=>({label:s.desc,value:e,ratio:s.ratio}))}e=e.filter(e=>"auto"!==e.value);const s=e=>{const s=e.parsedInfo?.multiplier??e.ratio??1,t=Number(s);return Number.isNaN(t)?1:t};e.sort((e,t)=>{const a=s(e),r=s(t);return a!==r?a-r:String(e.value).localeCompare(String(t.value))}),R(e),W(e)}else d(l(t))})()},[a.editingToken.id]),e.useEffect(()=>{if(a.visiable)if(te){const e={name:"",remain_quota:0,expired_time:-1,unlimited_quota:!0,model_limits_enabled:!1,model_limits:[],allow_ips:"",group:"",routing_priority:"auto",tokenCount:1,mj_image_mode:"default",mj_custom_proxy:"",selected_groups:[],unlimited_quota:!1};y.current?.setValues(e),V([]),re({routing:!1,group:!1,expiry:!1,quota:!1,modelLimits:!1,allowIps:!1,midjourney:!1})}else if(B)(async()=>{g(!0);let e=await o.get(`/api/token/${a.editingToken.id}`);const{success:s,message:t,data:r}=e.data;if(s){-1!==r.expired_time&&(r.expired_time=m(r.expired_time)),r.model_limits=u(r.model_limits);try{p&&"function"==typeof p&&(r.remain_quota=p(r.remain_quota))}catch(l){console.error("🎯 二开功能:额度转换出错",l)}const e=r.group?r.group.split(",").map(e=>e.trim()).filter(e=>e&&"auto"!==e):[];V(e);const{group:s,...t}=r;y.current&&y.current.setValues({name:"",remain_quota:0,expired_time:-1,unlimited_quota:!0,model_limits_enabled:!1,model_limits:[],allow_ips:"",group:"",routing_priority:"auto",tokenCount:1,mj_image_mode:"default",mj_custom_proxy:"",selected_groups:[],...t,routing_priority:t.routing_priority??"auto",group:e.length>0?e[0]:"",selected_groups:e}),J(-1===r.expired_time?"never":"custom"),e.length>0&&ge(e[0])}else d(t);g(!1)})();else{J("never");const e={name:"",remain_quota:0,expired_time:-1,unlimited_quota:!0,model_limits_enabled:!1,model_limits:[],allow_ips:"",group:"",routing_priority:"auto",tokenCount:1,mj_image_mode:"default",mj_custom_proxy:"",selected_groups:[]};y.current?.setValues(e),V([])}else y.current?.reset(),V([]),J("never")},[a.visiable,a.editingToken.id]);const je=()=>{let e="";for(let s=0;s<6;s++)e+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(62*Math.random()));return e},ye=e=>{const s=e.filter(Boolean);V(s);const t=s[0]||"";y.current&&(y.current.setValue("group",t),y.current.setValue("selected_groups",s)),t&&ge(t)},fe=()=>{H(!0)};return s.jsxs(s.Fragment,{children:[s.jsx(qe,{visible:Y,keys:Z,groups:ee,onClose:()=>{X(!1),Q([]),se([])}}),s.jsx(_,{placement:te||B?"right":"left",title:s.jsxs(v,{children:[te?s.jsx(q,{color:"orange",shape:"circle",children:l("批量修改")}):B?s.jsx(q,{color:"blue",shape:"circle",children:l("更新")}):s.jsx(q,{color:"green",shape:"circle",children:l("新建")}),s.jsx(Oe,{heading:4,className:"m-0",children:te?`${l("批量修改令牌")} (${a.batchTokenIds?.length||0}
1)`:l(B?"更新令牌信息":"创建新的令牌")})]}),bodyStyle:{padding:"0"},visible:a.visiable,width:j?"100%":600,footer:s.jsx("div",{className:"flex justify-end p-4",style:{backgroundColor:"hsl(var(--secondary))"},children:s.jsxs(v,{children:[s.jsx(w,{theme:"solid",className:"!rounded-lg",onClick:()=>y.current?.submitForm(),icon:s.jsx(me,{size:16}),loading:x,children:l("提交")}),s.jsx(w,{theme:"light",className:"!rounded-lg",type:"primary",onClick:le,icon:s.jsx(ue,{size:16}),children:l("取消")})]})}),closeIcon:null,onCancel:()=>le(),children:s.jsx(k,{spinning:x,children:s.jsx(N,{initValues:{name:"",remain_quota:0,expired_time:-1,unlimited_quota:!0,model_limits_enabled:!1,model_limits:[],allow_ips:"",group:"",routing_priority:"auto",tokenCount:1,mj_image_mode:"default",mj_custom_proxy:"",selected_groups:[]},getFormApi:e=>y.current=e,onSubmit:async e=>{if(te)return(async e=>{const s=a.batchTokenIds||[];if(0!==s.length)if(0!==Object.entries(ae).filter(([,e])=>e).length){g(!0);try{const r={ids:s},n=[];if(ae.group){n.push("group");const s=M.filter(Boolean);r.group=s.length>0?s.join(","):e.group||""}if(ae.routing&&(n.push("routing_priority"),r.routing_priority=e.routing_priority??""),ae.expiry)if(n.push("expired_time"),-1!==e.expired_time){let s=Date.parse(e.expired_time);if(isNaN(s))return d(l("过期时间格式错误!")),void g(!1);r.expired_time=Math.ceil(s/1e3)}else r.expired_time=-1;if(ae.quota){n.push("remain_quota"),n.push("unlimited_quota");try{r.remain_quota=h&&"function"==typeof h?parseInt(h(e.remain_quota)):parseInt(e.remain_quota)}catch(t){r.remain_quota=parseInt(e.remain_quota)}r.unlimited_quota=e.unlimited_quota}ae.modelLimits&&(n.push("model_limits"),r.model_limits=e.model_limits.join(","),r.model_limits_enabled=e.model_limits.length>0),ae.allowIps&&(n.push("allow_ips"),r.allow_ips=e.allow_ips||""),ae.midjourney&&(n.push("mj_image_mode"),n.push("mj_custom_proxy"),r.mj_image_mode=e.mj_image_mode||"default",r.mj_custom_proxy=e.mj_custom_proxy||""),r.update_fields=n;const c=await o.put("/api/token/batch",r);c?.data?.success?(i(l("已批量更新 {{num}} 个令牌!",{num:c.data.data||0})),a.refresh(),a.handleClose()):d(c?.data?.message||l("批量更新失败"))}catch(r){d(r.message)}g(!1),y.current?.setValues({name:"",remain_quota:0,expired_time:-1,unlimited_quota:!0,model_limits_enabled:!1,model_limits:[],allow_ips:"",group:"",routing_priority:"auto",tokenCount:1,mj_image_mode:"default",mj_custom_proxy:"",selected_groups:[]}),V([]),re({routing:!1,group:!1,expiry:!1,quota:!1,modelLimits:!1,allowIps:!1,midjourney:!1})}else d(l("请至少选择一个要修改的字段!"));else d(l("没有选择要修改的令牌!"))})(e);if(g(!0),B){let{tokenCount:t,...r}=e;try{r.remain_quota=h&&"function"==typeof h?parseInt(h(r.remain_quota)):parseInt(r.remain_quota)}catch(s){console.error("🎯 二开功能:额度转换出错",s),r.remain_quota=parseInt(r.remain_quota)}if(-1!==r.expired_time){let e=Date.parse(r.expired_time);if(isNaN(e))return d(l("过期时间格式错误!")),void g(!1);r.expired_time=Math.ceil(e/1e3)}r.model_limits=r.model_limits.join(","),r.model_limits_enabled=r.model_limits.length>0,r.routing_priority=r.routing_priority??"auto";const n=M.filter(Boolean),c=n.length>0?n.join(","):r.group;r.group=c;let m=await o.put("/api/token/",{...r,id:parseInt(a.editingToken.id)});const{success:u,message:p}=m.data;u?(i(l("令牌更新成功!")),a.refresh(),a.handleClose()):d(l(p))}else{const t=parseInt(e.tokenCount,10)||1;let r=0;const n=[];for(let a=0;a<t;a++){let{tokenCount:t,...i}=e;const c=""===e.name.trim()?"default":e.name.trim();0!==a||""===e.name.trim()?i.name=`${c}-${je()}`:i.name=c;try{i.remain_quota=h&&"function"==typeof h?parseInt(h(i.remain_quota)):parseInt(i.remain_quota)}catch(s){console.error("🎯 二开功能:创建令牌-额度转换出错",s),i.remain_quota=parseInt(i.remain_quota)}if(-1!==i.expired_time){let e=Date.parse(i.expired_time);if(isNaN(e)){d(l("过期时间格式错误!")),g(!1);break}i.expired_time=Math.ceil(e/1e3)}i.model_limits=i.model_limits.join(","),i.model_limits_enabled=i.model_limits.length>0,i.routing_priority=i.routing_priority??"auto";
1const m=M.filter(Boolean).join(",");i.group=m;let u=await o.post("/api/token/",i);const{success:p,message:x}=u.data;if(!p){d(l(x));break}{r++;const e=u.data?.data;"string"==typeof e&&e.startsWith("sk-")&&n.push(e)}}r>0&&(a.refresh(),a.handleClose(),n.length>0?(Q(n),se(M.filter(Boolean)),X(!0)):i(l("令牌创建成功,请在列表页面点击复制获取令牌!")))}g(!1),y.current?.setValues({name:"",remain_quota:0,expired_time:-1,unlimited_quota:!0,model_limits_enabled:!1,model_limits:[],allow_ips:"",group:"",routing_priority:"auto",tokenCount:1,mj_image_mode:"default",mj_custom_proxy:"",selected_groups:[]}),V([]),J("never")},children:({values:e})=>s.jsxs("div",{className:"p-6 space-y-6",children:[s.jsx(N.Input,{field:"routing_priority",style:{display:"none"}}),s.jsxs(C,{className:"!rounded-2xl shadow-sm border-0",children:[s.jsxs("div",{className:"flex items-center mb-4",children:[s.jsx(S,{size:"small",color:"blue",className:"mr-3 shadow-md",children:s.jsx(ie,{size:16})}),s.jsxs("div",{children:[s.jsx(Ae,{className:"text-lg font-medium",children:l("基本信息")}),s.jsx("div",{className:"text-sm mt-1",style:{color:"hsl(var(--muted-foreground))"},children:l(te?"勾选需要修改的字段":"设置令牌的基本信息")})]})]}),s.jsxs($,{gutter:16,children:[!te&&s.jsx(z,{span:24,children:s.jsx(N.Input,{field:"name",label:l("名称"),placeholder:l("请输入名称"),rules:[{required:!0,message:l("请输入名称")}],showClear:!0})}),s.jsxs(z,{span:24,children:[te&&s.jsx(I,{checked:ae.routing,onChange:e=>re(s=>({...s,routing:e.target.checked})),className:"mb-2",children:s.jsx(Ae,{strong:!0,children:l("修改智能路由")})}),s.jsxs("div",{style:te&&!ae.routing?{opacity:.4,pointerEvents:"none"}:{},children:[s.jsx(Be,{value:e.routing_priority,disabled:te&&!ae.routing,t:l,onChange:e=>{y.current?.setValue("routing_priority",e)}}),e.routing_priority?s.jsxs("div",{className:"flex items-start gap-1.5 mt-2 rounded-md px-2.5 py-2 text-xs leading-relaxed",style:{backgroundColor:"hsl(217 91% 60% / 0.08)",color:"hsl(217 60% 45%)"},children:[s.jsx(ne,{size:13,className:"mt-0.5 flex-shrink-0"}),s.jsx("span",{children:l("智能路由已激活 — 系统自动在您所有可访问分组中选择最优渠道,以下分组设置将被忽略。")})]}):s.jsx("div",{className:"flex items-start gap-1.5 mt-2 rounded-md px-2.5 py-2 text-xs leading-relaxed",style:{backgroundColor:"hsl(0 0% 50% / 0.08)",color:"var(--semi-color-text-2)"},children:s.jsx("span",{children:l("智能路由已关闭 — 将按下方手动选择的分组路由请求。")})})]})]}),s.jsxs(z,{span:24,children:[te&&s.jsx(I,{checked:ae.group,onChange:e=>re(s=>({...s,group:e.target.checked})),className:"mb-2",children:s.jsx(Ae,{strong:!0,children:l("修改分组")})}),s.jsx("div",{style:te&&!ae.group||!te&&e.routing_priority?{opacity:.4,pointerEvents:"none"}:{},children:L.length>0?s.jsx("div",{children:s.jsx(Re,{groups:L,selectedGroups:M,onGroupsChange:ye})}):s.jsxs("div",{children:[s.jsx(Ae,{strong:!0,className:"block mb-2",children:l("令牌分组")}),s.jsxs("div",{className:"text-center py-8",style:{color:"hsl(var(--muted-foreground))"},children:[s.jsx(oe,{size:48,className:"mx-auto mb-4 opacity-30"}),s.jsx(Ae,{type:"secondary",children:l("正在加载分组数据...")}),s.jsx(Ae,{type:"tertiary",className:"block text-sm mt-2",children:l("如果长时间未显示,请检查网络连接或刷新页面")})]})]})})]}),s.jsxs(z,{span:24,children:[te&&s.jsx(I,{checked:ae.expiry,onChange:e=>re(s=>({...s,expiry:e.target.checked})),className:"mb-2",children:s.jsx(Ae,{strong:!0,children:l("修改过期时间")})}),s.jsx("div",{style:te&&!ae.expiry?{opacity:.4,pointerEvents:"none"}:{},children:s.jsxs($,{gutter:16,children:[s.jsx(z,{xs:24,sm:24,md:24,lg:12,xl:12,children:s.jsx(N.DatePicker,{field:"expired_time",label:l("过期时间"),type:"dateTime",placeholder:l("请选择过期时间"),rules:te?[]:[{required:!0,message:l("请选择过期时间")},{validator:(e,s)=>{if(-1===s||!s)return Promise.resolve();const t=Date.parse(s);return isNaN(t)?Promise.reject(l("过期时间格式错误!")):t<=Date.now()?Promise.reject(l("过期时间不能早于当前时间!")):Promise.resolve()}}],showClear:!0,onChange:e=>{J(-1===e||null==e?"never":"custom")}})}),s.jsx(z,{xs:24,sm:24,md:24,lg:12,xl:12,children:s.jsx(N.Slot,{label:te?"":l("过期时间快捷设置"),children:s.jsxs(v,{wrap:!0,children:[s.jsx(w,{theme:"light",type:"never"===G?"primary":"tertiary",size:"small",onClick:()=>he(0,0,0,0),className:"!rounded-lg",children:l("永不过期")}),s.jsx(w,{theme:"light",type:"1m"===G?"primary":"tertiary",size:"small",onClick:()=>he(1,0,0,0),className:"!rounded-lg",children:l("一个月")}),s.jsx(w,{theme:"light",type:"1d"===G?"primary":"tertiary",size:"small",onClick:()=>he(0,1,0,0),className:"!rounded-lg",children:l("一天")}),s.jsx(w,{theme:"light",type:"1h"===G?"primary":"tertiary",size:"small",onClick:()=>he(0,0,1,0),className:"!rounded-lg",children:l("一小时")}),s.jsx(w,{theme:"light",type:"eom"===G?"primary":"tertiary",size:"small",onClick:xe,className:"!rounded-lg",children:l("月底")})]})})})]})})]}),!B&&!te&&s.jsx(z,{span:24,children:s.jsx(N.InputNumber,{field:"tokenCount",label:l("新建数量"),min:1,extraText:l("批量创建时会在名称后自动添加随机后缀"),rules:[{required:!0,message:l("请输入新建数量")}]})})]})]}),s.jsxs(C,{className:"!rounded-2xl shadow-sm border-0",children:[s.jsxs("div",{className:"flex items-center mb-4",children:[te&&s.jsx(I,{checked:ae.quota,onChange:e=>re(s=>({...s,quota:e.target.checked})),className:"mr-2"}),s.jsx(S,{size:"small",color:"green",className:"mr-3 shadow-md",children:s.jsx(ce,{size:16})}),s.jsxs("div",{children:[s.jsx(Ae,{className:"text-lg font-medium",children:l("额度设置")}),s.jsx("div",{className:"text-sm mt-1",style:{color:"hsl(var(--muted-foreground))"}
1,children:l("设置令牌可用额度和数量")})]})]}),s.jsx("div",{style:te&&!ae.quota?{opacity:.4,pointerEvents:"none"}:{},children:s.jsxs($,{gutter:16,children:[s.jsx(z,{span:24,children:s.jsxs("div",{className:"flex gap-3",children:[s.jsx(N.AutoComplete,{field:"remain_quota",label:l("额度"),placeholder:l("请输入额度"),type:"number",disabled:e.unlimited_quota,extraText:(()=>{if(!e.remain_quota)return"";const s=parseFloat(e.remain_quota);if(isNaN(s))return"";const t=parseFloat(localStorage.getItem("quota_per_unit"))||5e5;return n(s*t,2)})(),rules:e.unlimited_quota||te?[]:[{required:!0,message:l("请输入额度")}],data:[{value:1,label:"1$"},{value:10,label:"10$"},{value:50,label:"50$"},{value:100,label:"100$"},{value:500,label:"500$"},{value:1e3,label:"1000$"},{value:5e3,label:"5000$"},{value:1e4,label:"10000$"},{value:5e4,label:"50000$"},{value:1e5,label:"100000$"},{value:5e5,label:"500000$"},{value:1e6,label:"1000000$"}],className:"flex-1"}),s.jsx(w,{theme:"light",onClick:fe,disabled:e.unlimited_quota,className:"mt-8 !rounded-lg",children:l("增加额度")})]})}),s.jsx(z,{span:24,children:s.jsx(N.Switch,{field:"unlimited_quota",label:l("无限额度"),size:"large",extraText:l("令牌的额度仅用于限制令牌本身的最大额度使用量,实际的使用受到账户的剩余额度限制")})})]})})]}),s.jsxs(C,{className:"!rounded-2xl shadow-sm border-0",children:[s.jsxs("div",{className:"flex items-center mb-4",children:[te&&s.jsx(I,{checked:ae.modelLimits,onChange:e=>re(s=>({...s,modelLimits:e.target.checked})),className:"mr-2"}),s.jsx(S,{size:"small",color:"purple",className:"mr-3 shadow-md",children:s.jsx(de,{size:16})}),s.jsxs("div",{children:[s.jsx(Ae,{className:"text-lg font-medium",children:l("访问限制")}),s.jsx("div",{className:"text-sm mt-1",style:{color:"hsl(var(--muted-foreground))"},children:l("设置令牌的访问限制")})]})]}),s.jsx("div",{style:te&&!ae.modelLimits?{opacity:.4,pointerEvents:"none"}:{},children:s.jsxs($,{gutter:16,children:[s.jsx(z,{span:24,children:s.jsx(N.Select,{field:"model_limits",label:l("模型限制列表"),placeholder:l("请选择该令牌支持的模型,留空支持所有模型"),multiple:!0,optionList:b,extraText:l("非必要,不建议启用模型限制"),searchPosition:"dropdown",searchPlaceholder:l("搜索模型..."),filter:(e,s)=>{if(!e)return!0;const t=(s?.value||"").toString(),a=(s?.label||s?.value||"").toString(),r=e.toString().toLowerCase();return t.toLowerCase().includes(r)||a.toLowerCase().includes(r)},showFilteredOnly:!0,showClear:!0})}),s.jsxs(z,{span:24,children:[te&&s.jsx(I,{checked:ae.allowIps,onChange:e=>re(s=>({...s,allowIps:e.target.checked})),className:"mb-2",children:s.jsx(Ae,{strong:!0,children:l("修改IP白名单")})}),s.jsx("div",{style:te&&!ae.allowIps?{opacity:.4,pointerEvents:"none"}:{},children:s.jsx(N.TextArea,{field:"allow_ips",label:l("IP白名单"),placeholder:l("允许的IP,一行一个,不填写则不限制"),autosize:!0,rows:2,extraText:l("请勿过度信任此功能,IP可能被伪造"),showClear:!0})})]})]})})]}),s.jsxs(C,{className:"!rounded-2xl shadow-sm border-0",children:[s.jsxs("div",{className:"flex items-center mb-4",children:[te&&s.jsx(I,{checked:ae.midjourney,onChange:e=>re(s=>({...s,midjourney:e.target.checked})),className:"mr-2"}),s.jsx(S,{size:"small",color:"violet",className:"mr-3 shadow-md",children:s.jsx(T,{size:16})}),s.jsxs("div",{children:[s.jsx(Ae,{className:"text-lg font-medium",children:l("Midjourney 设置")}),s.jsx("div",{className:"text-sm mt-1",style:{color:"hsl(var(--muted-foreground))"},children:l("配置图片代理方式")})]})]}),s.jsx("div",{style:te&&!ae.midjourney?{opacity:.4,pointerEvents:"none"}:{},children:s.jsxs($,{gutter:16,children:[s.jsx(z,{span:24,children:s.jsx(N.Select,{field:"mj_image_mode",label:l("图片代理方式"),placeholder:l("请选择图片代理方式"),optionList:[{value:"default",label:l("默认")}
1,{value:"origin",label:l("(origin) Discord 原链接(国外很快,国内无法访问)")},{value:"proxy",label:l("(proxy) 图片代理地址(国外很慢,国内可以访问)")}]})}),"proxy"===e.mj_image_mode&&s.jsx(z,{span:24,children:s.jsx(N.Input,{field:"mj_custom_proxy",label:l("自定义图片代理"),placeholder:l("请输入自定义图片代理地址"),extraText:l("替换 https://cdn.discordapp.com 的地址,必须以 https,http 开头"),showClear:!0})})]})})]})]})},B?"edit":"new")})}),s.jsx(f,{title:s.jsxs("div",{className:"flex items-center",children:[s.jsx(S,{size:"extra-small",color:"green",className:"mr-2",children:s.jsx(ce,{size:12})}),l("增加额度")]}),visible:E,onOk:()=>{const e=y.current?.getValue("remain_quota")||0,s=parseFloat(e)+parseFloat(D);y.current?.setValue("remain_quota",s.toFixed(2)),H(!1),F(0)},onCancel:()=>H(!1),closeOnEsc:!0,centered:!0,className:"!rounded-2xl",okText:l("确认增加"),cancelText:l("取消"),children:s.jsxs("div",{className:"py-4",children:[s.jsx("div",{className:"mb-2",children:s.jsx("label",{className:"text-sm font-medium",children:l("增加金额")})}),s.jsx(A,{prefix:"$",placeholder:l("请输入要增加的额度"),value:D,onChange:e=>F(e),className:"w-full",min:0,step:1,precision:2})]})}),s.jsx(f,{title:s.jsxs("div",{className:"flex items-center",children:[s.jsx(S,{size:"extra-small",color:"blue",className:"mr-2",children:s.jsx(pe,{size:12})}),l("分组说明")]}),visible:K,onOk:()=>U(!1),onCancel:()=>U(!1),width:700,centered:!0,className:"!rounded-2xl",footer:s.jsx("div",{className:"flex justify-center",children:s.jsx(w,{type:"primary",theme:"solid",onClick:()=>U(!1),className:"!rounded-lg px-8",children:l("知道了")})}),children:s.jsx("div",{className:"py-4",children:s.jsxs("div",{className:"space-y-6",children:[s.jsxs("div",{children:[s.jsx(Oe,{heading:4,className:"mb-4",children:l("分组特点及选择指南")}),s.jsx(Ae,{type:"secondary",children:l("我们的分组系统经过精心设计,旨在满足不同用户的多样化需求。每个分组都有其独特的优势,您可以根据自身需求选择最适合的分组。")})]}),s.jsxs("div",{children:[s.jsx(Oe,{heading:5,className:"mb-3",children:l("分组特点对比")}),s.jsx("div",{className:"p-4 rounded-lg space-y-3",style:{backgroundColor:"hsl(var(--foreground) / 0.02)"},children:P.map((e,t)=>{const a=e.parsedInfo?.multiplier??e.ratio??1,r=e.parsedInfo?.description||e.label||e.description||"";return s.jsx(C,{className:"!rounded-lg border p-3",children:s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx(Ae,{strong:!0,children:e.value}),s.jsx(Ae,{type:"secondary",className:"block text-sm mt-1",children:r})]}),s.jsxs(q,{color:Pe(a),children:[a,"倍"]})]})},`${e.value}-${t}`)})})]}),s.jsxs("div",{children:[s.jsx(Oe,{heading:5,className:"mb-3",children:l("选择建议")}),s.jsx("div",{className:"space-y-2",children:[l("预算优先:选择低倍率分组,性价比更高"),l('稳定优先:选择标注"稳定性高"的分组,虽然费率较高但服务更可靠'),l("均衡选择:可以选择中等倍率分组,在成本和稳定性间取得平衡")].map((e,t)=>s.jsxs("div",{className:"flex items-start",children:[s.jsx("div",{className:"w-2 h-2 rounded-full mt-2 mr-3 flex-shrink-0",style:{backgroundColor:"hsl(var(--primary))"}}),s.jsx(Ae,{children:e})]},`suggestion-${t}`))})]})]})})})]})},{Text:Ve}=b;function Ee(e){return s.jsx(s.Fragment,{children:m(e)})}const He=()=>{const{t:a}=t(),r=Ne(),[n,m]=e.useState(null),p=[{title:a("名称"),dataIndex:"name"},{mobileTitle:a("状态"),title:s.jsxs("span",{className:"inline-flex items-center gap-1 select-none",children:[s.jsx("span",{children:a("状态")}),s.jsxs("span",{className:"inline-flex flex-col justify-center cursor-pointer",style:{gap:-2,lineHeight:0},role:"group","aria-label":a("按剩余额度排序"),onClick:e=>e.stopPropagation(),children:[s.jsx(fe,{size:11,style:{display:"block",color:"asc"===n?"hsl(var(--primary))":"hsl(var(--muted-foreground))",marginBottom:-3},onClick:e=>{e.stopPropagation(),"asc"===n?(m(null),R(1),ue(1,h,null)):(m("asc"),R(1),ue(1,h,"asc"))}}),s.jsx(ve,{size:11,style:{display:"block",color:"desc"===n?"hsl(var(--primary))":"hsl(var(--muted-foreground))"},onClick:e=>{e.stopPropagation(),"desc"===n?(m(null),R(1),ue(1,h,null)):(m("desc"),R(1),ue(1,h,"desc"))}})]})]}),dataIndex:"status",key:"status",render:(e,t)=>{const r=1===e,l=parseInt(t.used_quota)||0,i=parseInt(t.remain_quota)||0,n=l+i,o=n>0?i/n*100:0;let c="black",d=a("未知状态");r?0!==o||t.unlimited_quota?(c="green",d=a("已启用")):(c="yellow",d=a("已用尽")):2===e?(c="red",d=a("已禁用")):3===e?(c="yellow",d=a("已过期")):4===e&&(c="grey",d=a("已耗尽"));const m="green"===c?"hsl(var(--success))":"red"===c?"hsl(var(--destructive))":"yellow"===c?"hsl(var(--warning))":"hsl(var(--muted-foreground))",u=s.jsxs("div",{className:"flex flex-col gap-1 items-end",style:{minWidth:120},children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(O,{size:"small",checked:r,onChange:e=>
1{xe(t.id,e?"enable":"disable",t)},"aria-label":"token status switch"}),s.jsxs("span",{className:"flex items-center gap-1 text-xs font-medium text-foreground",children:[s.jsx("span",{className:"inline-block w-1.5 h-1.5 rounded-full flex-shrink-0",style:{backgroundColor:m}}),d]})]}),t.unlimited_quota?s.jsx("span",{className:"text-[11px] text-foreground/40 text-right",children:a("无限额度")}):s.jsxs("div",{className:"space-y-0.5 w-full",children:[s.jsxs("div",{className:"flex justify-between text-[11px] text-foreground/50",children:[s.jsx("span",{children:x(i)}),s.jsxs("span",{className:"text-foreground/30",children:["/ ",x(n)]})]}),s.jsx(J,{percent:0===o?1:o,stroke:(p=o,100===p?"hsl(var(--success))":0===p?"hsl(var(--warning))":p<=10?"hsl(var(--destructive))":p<=30?"hsl(var(--warning))":void 0),showInfo:!1,"aria-label":"quota usage",style:{width:"100%",marginTop:0,marginBottom:0}})]})]});var p;return t.unlimited_quota?s.jsx(P,{content:s.jsx("div",{className:"text-xs",children:s.jsxs("div",{children:[a("已用额度"),": ",x(l)]})}),position:"top",showArrow:!0,children:u}):s.jsx(P,{content:s.jsxs("div",{className:"text-xs",children:[s.jsxs("div",{children:[a("已用额度"),": ",x(l)]}),s.jsxs("div",{children:[a("剩余额度"),": ",x(i)," (",o.toFixed(0),"%)"]}),s.jsxs("div",{children:[a("总额度"),": ",x(n)]})]}),children:u})}},{title:a("分组"),dataIndex:"group",key:"group",render:e=>"auto"===e?s.jsx(P,{content:a("旧版 auto 分组已不再作为新令牌入口,请改用令牌智能路由。"),position:"top",children:s.jsxs(q,{color:"orange",shape:"circle",children:[" ",a("旧 auto 分组")," "]})}):g(e)},{title:a("智能路由"),dataIndex:"routing_priority",key:"routing_priority",render:e=>{if(!e)return s.jsx(q,{color:"grey",shape:"circle",children:a("手动")});const t={auto:{color:"blue",label:a("智能自动")},price:{color:"green",label:a("价格优先")},speed:{color:"orange",label:a("速度优先")},success_rate:{color:"red",label:a("成功率优先")}}[e]||{color:"grey",label:a("未设置")};return s.jsx(q,{color:t.color,shape:"circle",children:t.label})}},{title:a("密钥"),key:"token_key",render:(e,t)=>{const a="sk-"+t.key,r="sk-"+t.key.slice(0,4)+"**********"+t.key.slice(-4),l=!!K[t.id];return s.jsx("div",{className:"w-[210px]",children:s.jsx(Y,{readOnly:!0,value:l?a:r,size:"small",suffix:s.jsxs("div",{className:"flex items-center",children:[s.jsx(w,{theme:"borderless",size:"small",type:"tertiary",icon:l?s.jsx(re,{size:16}):s.jsx(ae,{size:16}),"aria-label":"toggle token visibility",onClick:e=>{e.stopPropagation(),U(e=>({...e,[t.id]:!l}))}}),s.jsx(w,{theme:"borderless",size:"small",type:"tertiary",icon:s.jsx(le,{size:16}),"aria-label":"copy token key",onClick:async e=>{e.stopPropagation(),await he(a)}})]})})})}},{title:a("可用模型"),dataIndex:"model_limits",render:(e,t)=>{if(t.model_limits_enabled&&e){const t=u(e),r=c(a),l=[],i=new Set;Object.entries(r).forEach(([e,a])=>{if("all"===e)return;if(!a.icon||!a.filter)return;const r=t.filter(e=>a.filter({model_name:e}));r.length>0&&(l.push(s.jsx(P,{content:r.join(", "),position:"top",showArrow:!0,children:s.jsx(S,{size:"extra-extra-small",alt:a.label,style:{background:"transparent"},children:a.icon})},e)),r.forEach(e=>i.add(e)))});const n=t.filter(e=>!i.has(e));return n.length>0&&l.push(s.jsx(P,{content:n.join(", "),position:"top",showArrow:!0,children:s.jsx(S,{size:"extra-extra-small",alt:"unknown",children:a("其他")})},"unknown")),s.jsx(X,{size:"extra-extra-small",children:l})}return s.jsx(q,{color:"white",shape:"circle",children:a("无限制")})}},{title:a("IP限制"),dataIndex:"allow_ips",render:e=>{if(!e||""===e.trim())return s.jsx(q,{color:"white",shape:"circle",children:a("无限制")});const t=e.split("\n").map(e=>e.trim()).filter(Boolean),r=t.slice(0,1),l=t.length-r.length,i=r.map((e,t)=>s.jsx(q,{shape:"circle",children:e},t));return l>0&&i.push(s.jsx(P,{content:t.slice(1).join(", "),position:"top",showArrow:!0,children:s.jsx(q,{shape:"circle",children:"+"+l})},"extra")),s.jsx(v,{wrap:!0,children:i})}},{title:a("创建时间"),dataIndex:"created_time",render:(e,t,a)=>s.jsx("div",{children:Ee(e)})},{title:a("过期时间"),dataIndex:"expired_time",render:(e,t,r)=>s.jsx("div",{children:-1===t.expired_time?a("永不过期"):Ee(e)})},{title:"",dataIndex:"operate",fixed:"right",render:(e,t,r)=>s.jsxs(v,{wrap:!0,children:[s.jsx(w,{type:"tertiary",size:"small",onClick:()=>{H(t),k(!0)},children:a("编辑")}),s.jsx(w,{theme:"borderless",type:"danger",size:"small",onClick:()=>{f.confirm({title:a("确定是否要删除此令牌?"),content:a("此修改将不可逆"),onOk:()=>{(async()=>{await xe(t.id,"delete",t),await pe()})()}})},children:a("删除")})]})}],[h,b]=e.useState(j),[_,k]=e.useState(!1),[C,$]=e.useState([]),[z,I]=e.useState([]),[T,A]=e.useState(h),[W,B]=e.useState(!0),[L,R]=e.useState(1),[M,V]=e.useState(!1),[E,H]=e.useState({id:void 0}),[D,F]=we("tokens"),[K,U]=e.useState({}),[G,se]=e.useState(!1),[te,ne]=e.useState([]),[oe,ce]=e.useState(!1),[de,me]=e.useState(null),ue=async(e=1,s=h,t)=>{B(!0);try{const a=void 0!==t?t:n,{searchKeyword:l,searchToken:i,searchGroup:c}=(()=>{const e=de?de.getValues():{};return{searchKeyword:e.searchKeyword||"",searchToken:e.searchToken||"",searchGroup:e.searchGroup||""}})(),m=new URLSearchParams;m.set("p",e),m.set("size",s),l&&m.set("keyword",l),i&&m.set("token",
1i),c&&m.set("group",c),"asc"!==a&&"desc"!==a||(m.set("sort","remain_quota"),m.set("order",a));const u=await o.get(`/api/token/filter?${m.toString()}`),{success:p,message:x,data:g}=u.data;p?($((r=g).items||[]),A(r.total||0),R(r.page||1),b(r.page_size||h)):d(x)}catch(l){console.error("加载令牌列表失败:",l),d(a("加载令牌列表失败,请重试"))}finally{B(!1)}var r},pe=async(e=L)=>{await ue(e,h),I([])},he=async e=>{await l(e)?i(a("已复制到剪贴板")+"!"):f.error({title:a("无法复制到剪贴板,请手动复制"),content:e,size:"large"})};e.useEffect(()=>{ue(1).then().catch(e=>{d(e)}),(async()=>{try{const e=await o.get("/api/user/self/groups"),{success:s,data:t}=e.data;if(s&&t?.data){const e=t.data,s=Object.keys(e).filter(e=>"auto"!==e).map(s=>({label:e[s]?`${s} `:s,value:s}));ne(s)}}catch(e){console.error("加载分组列表失败:",e)}})()},[h]);const xe=async(e,s,t)=>{B(!0);try{let r,l={id:e};switch(s){case"delete":r=await o.delete(`/api/token/${e}/`);break;case"enable":l.status=1,r=await o.put("/api/token/?status_only=true",l);break;case"disable":l.status=2,r=await o.put("/api/token/?status_only=true",l)}const{success:n,message:c}=r.data;if(n){i(a("操作成功完成!"));let e=r.data.data,l=[...C];"delete"===s||(t.status=e.status),$(l)}else d(c)}catch(r){console.error("令牌操作失败:",r),d(a("令牌操作失败,请重试"))}finally{B(!1)}},ge={selectedRowKeys:z.map(e=>e.id),onSelect:(e,s)=>{},onSelectAll:(e,s)=>{},onChange:(e,s)=>{I(s)}},je=s.jsx("div",{className:"mb-2",children:s.jsxs("div",{className:"flex flex-col md:flex-row justify-between items-start md:items-center gap-2 w-full",children:[s.jsxs("div",{className:"flex items-center text-foreground/50",children:[s.jsx(ie,{size:16,className:"mr-2"}),s.jsx(Ve,{children:a("令牌用于API访问认证,可以设置额度限制和模型权限。")})]}),!r&&s.jsx(w,{type:"tertiary",className:"w-full md:w-auto",onClick:()=>F(!D),size:"small",children:a(D?"自适应列表":"紧凑列表")})]})}),ye=s.jsxs("div",{className:"flex flex-wrap gap-2 w-full md:w-auto",children:[s.jsx(w,{type:"primary",className:"flex-1 md:flex-initial",onClick:()=>{H({id:void 0}),k(!0)},size:"small",children:a("添加令牌")}),s.jsx(w,{type:"tertiary",className:"flex-1 md:flex-initial",onClick:()=>{0!==z.length?f.info({title:a("复制令牌"),icon:null,content:a("请选择你的复制方式"),footer:s.jsxs(v,{children:[s.jsx(w,{type:"tertiary",onClick:async()=>{let e="";for(let s=0;s<z.length;s++)e+=z[s].name+"    sk-"+z[s].key+"\n";await he(e),f.destroyAll()},children:a("名称+密钥")}),s.jsx(w,{onClick:async()=>{let e="";for(let s=0;s<z.length;s++)e+="sk-"+z[s].key+"\n";await he(e),f.destroyAll()},children:a("仅密钥")})]})}):d(a("请至少选择一个令牌!"))},size:"small",children:a("复制所选令牌")}),s.jsx(w,{type:"tertiary",className:"w-full md:w-auto",onClick:()=>{0!==z.length?se(!0):d(a("请至少选择一个令牌!"))},size:"small",children:a("批量修改")}),s.jsx(w,{type:"tertiary",className:"w-full md:w-auto",onClick:async()=>{ce(!0);try{const e=new URLSearchParams;z.length>0&&e.set("ids",z.map(e=>e.id).join(","));const s=await o.get(`/api/token/export?${e.toString()}`,{responseType:"blob"}),t=new Blob([s.data],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}),r=window.URL.createObjectURL(t),l=document.createElement("a");l.href=r;const n=new Date,c=`${n.getFullYear()}${String(n.getMonth()+1).padStart(2,"0")}${String(n.getDate()).padStart(2,"0")}_${String(n.getHours()).padStart(2,"0")}${String(n.getMinutes()).padStart(2,"0")}${String(n.getSeconds()).padStart(2,"0")}`;l.download=`令牌列表_${c}.xlsx`,document.body.appendChild(l),l.click(),window.URL.revokeObjectURL(r),document.body.removeChild(l),i(a("导出成功"))}catch(e){d(a("导出失败,请重试")),console.error("导出令牌失败:",e)}finally{ce(!1)}},loading:oe,size:"small",children:z.length>0?a("导出所选令牌"):a("导出全部令牌")}),s.jsx(w,{type:"tertiary",className:"w-full md:w-auto",onClick:()=>{0!==z.length?f.confirm({title:a("批量删除令牌"),content:s.jsx("div",{children:a("确定要删除所选的 {{num}} 个令牌吗?",{num:z.length})}),onOk:()=>(async()=>
1{if(0!==z.length){B(!0);try{const e=z.map(e=>e.id),s=await o.post("/api/token/batch",{ids:e});if(s?.data?.success){const e=s.data.data||0;i(a("已删除 {{num}} 个令牌!",{num:e})),await pe(),setTimeout(()=>{0===C.length&&L>1&&pe(L-1)},100)}else d(s?.data?.message||a("删除失败"))}catch(e){d(e.message)}finally{B(!1)}}else d(a("请先选择要删除的令牌!"))})()}):d(a("请至少选择一个令牌!"))},size:"small",children:a("删除所选令牌")})]}),Ce=s.jsx(N,{initValues:{searchKeyword:"",searchToken:"",searchGroup:""},getFormApi:e=>me(e),onSubmit:async()=>{V(!0);try{await ue(1)}finally{V(!1)}},allowEmpty:!0,autoComplete:"on",layout:"horizontal",trigger:"change",stopValidateWithError:!1,className:"w-full md:w-auto",children:s.jsxs("div",{className:"flex flex-col md:flex-row items-center gap-4 w-full md:w-auto",children:[s.jsx("div",{className:"relative w-full md:w-56",children:s.jsx(N.Input,{field:"searchKeyword",name:"tokens_search_keyword",prefix:s.jsx(be,{size:16}),placeholder:a("搜索关键字"),showClear:!0,pure:!0,size:"small"})}),s.jsx("div",{className:"relative w-full md:w-56",children:s.jsx(N.Input,{field:"searchToken",name:"tokens_search_token",prefix:s.jsx(be,{size:16}),placeholder:a("密钥"),showClear:!0,pure:!0,size:"small"})}),s.jsx("div",{className:"relative w-full md:w-44",children:s.jsx(N.Select,{field:"searchGroup",placeholder:a("筛选分组"),optionList:[{label:a("全部分组"),value:""},...te],showClear:!0,size:"small",pure:!0,style:{width:"100%"}})}),s.jsxs("div",{className:"flex gap-2 w-full md:w-auto",children:[s.jsx(w,{type:"tertiary",htmlType:"submit",loading:W||M,className:"flex-1 md:flex-initial md:w-auto",size:"small",children:a("查询")}),s.jsx(w,{type:"tertiary",onClick:()=>{de&&(de.reset(),m(null),setTimeout(()=>{ue(1,h,null)},100))},className:"flex-1 md:flex-initial md:w-auto",size:"small",children:a("重置")})]})]})}),Se=y({currentPage:L,pageSize:h,total:T,onPageChange:e=>{ue(e,h).then()},onPageSizeChange:async e=>{b(e),await ue(1,e)},isMobile:r,t:a});return s.jsxs(s.Fragment,{children:[s.jsx(Me,{refresh:pe,editingToken:E,visiable:_,handleClose:()=>{k(!1),setTimeout(()=>{H({id:void 0})},500)}}),s.jsx(Me,{refresh:pe,editingToken:{id:void 0},visiable:G,handleClose:()=>{se(!1)},isBatchMode:!0,batchTokenIds:z.map(e=>e.id)}),s.jsx(ke,{type:"type1",shadows:"always",bordered:!1,descriptionArea:je,actionsArea:ye,searchArea:Ce,paginationArea:Se,children:s.jsx(_e,{columns:D?p.map(e=>{if("operate"===e.dataIndex){const{fixed:s,...t}=e;return t}return e}):p,dataSource:C,rowKey:"id",scroll:D?void 0:{x:"max-content"},loading:W,rowSelection:ge,onRow:(e,s)=>1!==e.status?{style:{background:"hsl(var(--border))"}}:{},empty:s.jsx(Z,{image:s.jsx(ee,{style:{width:150,height:150}}),darkModeImage:s.jsx(Q,{style:{width:150,height:150}}),description:a("搜索无结果"),style:{padding:30}}),className:"rounded-xl overflow-hidden",size:"middle",hidePagination:!0})})]})},De=()=>{const{t:r}=t(),[l]=e.useContext(a),[i,n]=e.useState(""),{Text:o}=b;return e.useEffect(()=>{const e=l?.status?.server_address||localStorage.getItem("status")&&JSON.parse(localStorage.getItem("status")).server_address||window.location.origin;n(e)},[l?.status]),s.jsx("div",{className:"px-2",children:s.jsx(He,{})})};export{De 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.