Files
Sub-Router/dist/assets/Tokens-BdD2zQiB.js
T
abingyydsandClaude Sonnet 4.6 3b8206284f feat: 所有模板 Home 页套餐卡片添加官方价格等价对比
提取 calcOfficialEquiv 为公共工具函数,7 个 Home 模板和
Packages 页面共用,自动选择折扣比例最大的模型展示等价额度。

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-25 03:46:01 +09:00

74 lines
17 KiB
JavaScript

import{r as o,e as E,f as I,j as e,z as C,h as P,i as W,k as U}from"./index-ClhW4pXr.js";import{u as K}from"./useTranslation-Pq_l7wMn.js";const F=()=>{var D;const{t}=K(),[v,_]=o.useState([]),[i,L]=o.useState(null),[S,m]=o.useState([]),[l,j]=o.useState(""),[p,A]=o.useState("claudecode"),[H,$]=o.useState(!0),[y,M]=o.useState(!1),[u,x]=o.useState(""),[h,k]=o.useState(!1),T=o.useRef(null),d=window.location.origin,N=[{id:"claudecode",name:"Claude Code",path:"~/.claude/settings.json"},{id:"openclaw",name:"OpenClaw",path:"~/.openclaw/openclaw.json"},{id:"opencode",name:"OpenCode",path:"~/.config/opencode/opencode.json"},{id:"cursor",name:"Cursor",path:"Settings → Models → OpenAI API Key"},{id:"curl",name:"cURL",path:"Terminal"},{id:"python",name:"Python SDK",path:"main.py"},{id:"anthropic",name:"Anthropic SDK",path:"main.py"}];o.useEffect(()=>{a()},[]),o.useEffect(()=>{i&&f(i)},[i]),o.useEffect(()=>{const s=n=>{T.current&&!T.current.contains(n.target)&&k(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[]);const a=async()=>{$(!0);try{const s=await E();if(s.data.success){const n=s.data.data||[];_(n),n.length>0&&L(n[0])}}catch{}$(!1)},f=async s=>{try{if(s.model_limits_enabled&&s.model_limits){const r=s.model_limits.split(",").filter(g=>g.trim());m(r),r.length>0&&j(r[0]);return}const n=await I();if(n.data.success&&n.data.data){const g=(Array.isArray(n.data.data)?n.data.data:n.data.data.items||[]).map(b=>b.model_name||b.id||b);m(g),g.length>0&&j(g[0])}}catch{}},c=s=>{const n=s.toLowerCase();return n.includes("claude")?{provider:"anthropic",api:"anthropic-messages"}:n.includes("gpt")||n.includes("o1")||n.includes("o3")?{provider:"openai",api:"openai-chat"}:n.includes("gemini")?{provider:"google",api:"google-chat"}:{provider:"openai",api:"openai-chat"}},w=()=>{if(!i||!l)return"";const s="sk-"+i.key;switch(p){case"claudecode":return`{
"env": {
"ANTHROPIC_API_KEY": "${s}",
"ANTHROPIC_BASE_URL": "${d}/",
"ANTHROPIC_MODEL": "${l}"
}
}`;case"openclaw":{const n=c(l);return`{
"provider": "${n.provider}",
"base_url": "${d}/",
"api": "${n.api}",
"api_key": "${s}",
"model": {
"id": "${l}",
"name": "${l}"
}
}`}case"opencode":return`{
"provider": {
"openai": {
"options": {
"baseURL": "${d}/v1",
"apiKey": "${s}"
},
"models": {
"${l}": {
"name": "${l}",
"options": {
"store": false
}
}
}
}
},
"$schema": "https://opencode.ai/config.json"
}`;case"cursor":return`API Key: ${s}
Base URL: ${d}/v1
Model: ${l}`;case"curl":return`curl ${d}/v1/chat/completions \\
-H "Content-Type: application/json" \\
-H "Authorization: Bearer ${s}" \\
-d '{
"model": "${l}",
"messages": [
{"role": "user", "content": "Hello!"}
]
}'`;case"python":return`from openai import OpenAI
client = OpenAI(
api_key="${s}",
base_url="${d}/v1"
)
response = client.chat.completions.create(
model="${l}",
messages=[
{"role": "user", "content": "Hello!"}
]
)
print(response.choices[0].message.content)`;case"anthropic":return`import anthropic
client = anthropic.Anthropic(
api_key="${s}",
base_url="${d}/"
)
message = client.messages.create(
model="${l}",
max_tokens=1024,
messages=[
{"role": "user", "content": "Hello!"}
]
)
print(message.content[0].text)`;default:return""}},z=()=>{var s;switch(p){case"curl":return"api-call.sh";case"python":return"main.py";case"anthropic":return"main.py";case"cursor":return"cursor-config.txt";default:return((s=N.find(n=>n.id===p))==null?void 0:s.path.split("/").pop())||"config.json"}},O=async()=>{const s=w();try{await navigator.clipboard.writeText(s)}catch{const r=document.createElement("textarea");r.value=s,r.style.position="fixed",r.style.opacity="0",document.body.appendChild(r),r.select(),document.execCommand("copy"),document.body.removeChild(r)}M(!0),C.success(t("config.copied")),setTimeout(()=>M(!1),2e3)},R=()=>{const s=w(),n=z(),r=new Blob([s],{type:"text/plain"}),g=URL.createObjectURL(r),b=document.createElement("a");b.href=g,b.download=n,b.click(),URL.revokeObjectURL(g),C.success(t("config.downloaded"))};if(H)return e.jsxs("div",{className:"glass rounded-2xl p-6 text-center",children:[e.jsx("div",{className:"w-8 h-8 border-2 border-brand-500/30 border-t-brand-500 rounded-full animate-spin mx-auto mb-2"}),e.jsx("p",{className:"text-sm text-page-secondary",children:t("config.loading")})]});if(v.length===0)return e.jsxs("div",{className:"glass rounded-2xl p-6 text-center",children:[e.jsx("svg",{className:"w-8 h-8 mx-auto mb-3 text-page-muted",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z"})}),e.jsx("p",{className:"text-sm text-page-secondary mb-1",children:t("config.loginPrompt")}),e.jsx("p",{className:"text-xs text-page-muted",children:t("config.loginDesc")})]});const B=w();return e.jsxs("div",{className:"glass rounded-2xl overflow-hidden",children:[e.jsxs("div",{className:"px-5 py-4 border-b border-page-divider",children:[e.jsxs("h4",{className:"font-semibold text-sm text-page flex items-center gap-2",children:[e.jsx("svg",{className:"w-4 h-4 text-brand-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),t("config.title")]}),e.jsx("p",{className:"text-xs text-page-muted mt-1",children:t("config.subtitle")})]}),e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-2 text-xs font-medium text-page-label mb-2",children:[e.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z"})}),t("config.selectKey")]}),e.jsx("select",{value:(i==null?void 0:i.id)||"",onChange:s=>{const n=v.find(r=>r.id===parseInt(s.target.value));L(n)},className:"input",children:v.map(s=>e.jsxs("option",{value:s.id,children:[s.name," (sk-",s.key.substring(0,16),"...)"]},s.id))})]}),S.length>0&&e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-2 text-xs font-medium text-page-label mb-2",children:[e.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"})}),t("config.selectModel")]}),e.jsxs("div",{className:"relative",ref:T,children:[e.jsx("input",{type:"text",value:h?u:l,onChange:s=>{x(s.target.value),k(!0)},onFocus:()=>{x(""),k(!0)},className:"input pr-8",placeholder:t("config.searchModel")}),e.jsx("svg",{className:"w-3.5 h-3.5 absolute right-3 top-1/2 -translate-y-1/2 text-page-muted pointer-events-none",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),h&&e.jsxs("div",{className:"absolute z-50 mt-1 w-full max-h-60 overflow-y-auto rounded-lg glass shadow-xl",children:[S.filter(s=>s.toLowerCase().includes(u.toLowerCase())).map(s=>e.jsx("button",{onClick:()=>{j(s),k(!1),x("")},className:`w-full text-left px-3 py-2 text-sm transition-colors hover:bg-page-surface-hover ${s===l?"text-brand-400 bg-brand-500/10":"text-page-secondary"}`,children:s},s)),S.filter(s=>s.toLowerCase().includes(u.toLowerCase())).length===0&&e.jsx("p",{className:"px-3 py-3 text-xs text-page-muted text-center",children:t("config.noModelMatch")})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-page-label mb-2 block",children:t("config.selectTool")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:N.map(s=>e.jsx("button",{onClick:()=>A(s.id),className:`px-3 py-1.5 rounded-lg text-xs font-medium transition-all ${p===s.id?"bg-brand-500 text-white shadow-sm":"bg-page-surface text-page-secondary hover:bg-page-surface-hover"}`,children:s.name},s.id))})]})]}),e.jsxs("div",{className:"border-t border-page-divider",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5 bg-page-inset",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-red-400"}),e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-yellow-400"}),e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-green-400"})]}),e.jsx("span",{className:"text-xs text-page-muted ml-1",children:(D=N.find(s=>s.id===p))==null?void 0:D.path})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:O,className:"p-1.5 rounded-md hover:bg-page-surface-hover transition-colors text-page-muted hover:text-page",title:t("config.copy"),children:y?e.jsx("svg",{className:"w-3.5 h-3.5 text-page-success",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}):e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),e.jsx("button",{onClick:R,className:"p-1.5 rounded-md hover:bg-page-surface-hover transition-colors text-page-muted hover:text-page",title:t("config.download"),children:e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})})]})]}),e.jsx("pre",{className:"p-4 text-xs leading-relaxed overflow-x-auto max-h-64 font-mono text-page-success",children:e.jsx("code",{children:B})})]})]})};function Y(){const{t}=K(),[v,_]=o.useState([]),[i,L]=o.useState(!0),[S,m]=o.useState(!1),[l,j]=o.useState(""),[p,A]=o.useState(!1),[H,$]=o.useState(null),[y,M]=o.useState(null),[u,x]=o.useState(null),h=o.useCallback(async()=>{L(!0);try{const a=await E();a.data.success&&_(a.data.data||[])}catch{}L(!1)},[]);o.useEffect(()=>{h()},[h]);const k=async a=>{var f;if(a.preventDefault(),!l.trim()){C.error(t("tokens.enterName"));return}A(!0);try{const c=await P({name:l.trim()});if(c.data.success){j(""),m(!1);const w=(f=c.data.data)==null?void 0:f.key;w&&M(w),await h()}}catch{}A(!1)},T=async a=>{try{(await W(a.id,{status:a.status===1?2:1})).data.success&&(C.success(a.status===1?t("tokens.tokenDisabled"):t("tokens.tokenEnabled")),await h())}catch{}},d=async()=>{if(u)try{(await U(u.id)).data.success&&(C.success(t("tokens.tokenDeleted")),x(null),await h())}catch{}},N=async a=>{try{await navigator.clipboard.writeText(a)}catch{const c=document.createElement("textarea");c.value=a,c.style.position="fixed",c.style.opacity="0",document.body.appendChild(c),c.select(),document.execCommand("copy"),document.body.removeChild(c)}$(a),C.success(t("tokens.copiedToClipboard")),setTimeout(()=>$(null),2e3)};return i?e.jsx("div",{className:"flex items-center justify-center min-h-[50vh]",children:e.jsx("div",{className:"w-8 h-8 border-2 border-brand-500/30 border-t-brand-500 rounded-full animate-spin"})}):e.jsxs("div",{className:"max-w-5xl mx-auto px-6 py-10",children:[e.jsxs("div",{className:"flex items-center justify-between mb-8",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-heading font-bold text-page",children:t("tokens.title")}),e.jsx("p",{className:"text-sm text-page-secondary mt-1",children:t("tokens.subtitle")})]}),e.jsx("button",{onClick:()=>m(!0),className:"btn-primary",children:t("tokens.newKey")})]}),S&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:()=>m(!1),children:e.jsxs("div",{className:"glass rounded-2xl p-6 w-full max-w-md",onClick:a=>a.stopPropagation(),children:[e.jsx("h2",{className:"text-lg font-semibold text-page mb-4",children:t("tokens.createApiKey")}),e.jsxs("form",{onSubmit:k,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-page-label mb-1.5",children:t("tokens.name")}),e.jsx("input",{type:"text",value:l,onChange:a=>j(a.target.value),className:"input",placeholder:t("tokens.namePlaceholder"),autoFocus:!0,required:!0})]}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx("button",{type:"button",onClick:()=>m(!1),className:"btn-secondary",children:t("tokens.cancel")}),e.jsx("button",{type:"submit",disabled:p,className:"btn-primary",children:t(p?"tokens.creating":"tokens.create")})]})]})]})}),y&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",children:e.jsxs("div",{className:"glass rounded-2xl p-6 w-full max-w-lg",children:[e.jsx("h2",{className:"text-lg font-semibold text-page mb-2",children:t("tokens.newApiKey")}),e.jsx("div",{className:"bg-yellow-500/10 border border-yellow-500/20 rounded-xl p-3 mb-4",children:e.jsx("p",{className:"text-sm text-page-warning",children:t("tokens.keyWarning")})}),e.jsxs("div",{className:"bg-page-inset rounded-xl p-4 flex items-center gap-3",children:[e.jsx("code",{className:"text-sm font-mono text-page-success flex-1 break-all select-all",children:y}),e.jsx("button",{onClick:()=>N(y),className:"btn-primary !px-4 !py-1.5 flex-shrink-0",children:t(H===y?"tokens.copied":"tokens.copy")})]}),e.jsx("div",{className:"flex justify-end mt-4",children:e.jsx("button",{onClick:()=>M(null),className:"btn-secondary",children:t("tokens.savedKey")})})]})}),u&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:()=>x(null),children:e.jsxs("div",{className:"glass rounded-2xl p-6 w-full max-w-sm",onClick:a=>a.stopPropagation(),children:[e.jsx("h2",{className:"text-lg font-semibold text-page mb-3",children:t("tokens.deleteToken")}),e.jsx("p",{className:"text-sm text-page-secondary mb-4",children:t("tokens.deleteConfirm",{name:u.name})}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx("button",{onClick:()=>x(null),className:"btn-secondary",children:t("tokens.cancel")}),e.jsx("button",{onClick:d,className:"px-6 py-2.5 rounded-xl bg-red-600 text-white text-sm font-medium hover:bg-red-500 transition-colors",children:t("tokens.delete")})]})]})}),v.length===0?e.jsxs("div",{className:"glass rounded-2xl p-12 text-center",children:[e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 rounded-2xl bg-page-surface flex items-center justify-center",children:e.jsx("svg",{className:"w-8 h-8 text-page-muted",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z"})})}),e.jsx("p",{className:"text-page-secondary mb-4",children:t("tokens.noKeys")}),e.jsx("button",{onClick:()=>m(!0),className:"btn-primary",children:t("tokens.createFirst")})]}):e.jsx("div",{className:"space-y-3",children:v.map(a=>e.jsxs("div",{className:"glass-sm rounded-xl p-5",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:`w-2.5 h-2.5 rounded-full flex-shrink-0 ${a.status===1?"bg-green-500":"bg-page-muted"}`}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx("p",{className:"text-sm font-medium text-page",children:a.name})}),e.jsx("span",{className:"text-xs text-page-muted hidden md:block",children:a.created_time?new Date(a.created_time*1e3).toLocaleDateString():""}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>T(a),className:`px-3 py-1 text-xs rounded-lg border transition-colors ${a.status===1?"border-green-500/30 text-page-success hover:bg-green-500/10":"border-page-divider text-page-secondary hover:bg-page-surface-hover"}`,children:a.status===1?t("tokens.enabled"):t("tokens.disabled")}),e.jsx("button",{onClick:()=>x(a),className:"px-3 py-1 text-xs rounded-lg border border-red-500/20 text-page-danger hover:bg-red-500/10 transition-colors",children:t("tokens.delete")})]})]}),a.key&&e.jsxs("div",{className:"mt-3 flex items-center gap-2 bg-page-inset rounded-lg px-3 py-2",children:[e.jsxs("code",{className:"text-xs font-mono text-page-muted flex-1 break-all select-all",children:["sk-",a.key]}),e.jsx("button",{onClick:()=>N("sk-"+a.key),className:"flex-shrink-0 px-2.5 py-1 text-xs rounded-md bg-page-surface text-page-secondary hover:bg-page-surface-hover hover:text-page transition-colors",children:H==="sk-"+a.key?t("tokens.copied"):t("tokens.copy")})]})]},a.id))}),e.jsx("div",{className:"mt-8",children:e.jsx(F,{})})]})}export{Y as default};