Spaces:
Paused
Paused
feat: eye toggle, use_count, deactivate btn, 14 models
Browse files- emergent2api/database.py +15 -1
- emergent2api/models.py +27 -4
- emergent2api/routes/admin.py +1 -0
- emergent2api/static/admin/index.html +80 -22
emergent2api/database.py
CHANGED
|
@@ -22,6 +22,7 @@ CREATE TABLE IF NOT EXISTS emergent_accounts (
|
|
| 22 |
refresh_token TEXT DEFAULT '',
|
| 23 |
user_id TEXT DEFAULT '',
|
| 24 |
balance REAL DEFAULT 0,
|
|
|
|
| 25 |
is_active BOOLEAN DEFAULT TRUE,
|
| 26 |
last_used TIMESTAMPTZ,
|
| 27 |
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
@@ -31,6 +32,18 @@ CREATE TABLE IF NOT EXISTS emergent_accounts (
|
|
| 31 |
CREATE INDEX IF NOT EXISTS idx_emergent_active ON emergent_accounts (is_active) WHERE is_active = TRUE;
|
| 32 |
"""
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
async def get_pool() -> asyncpg.Pool:
|
| 36 |
global _pool
|
|
@@ -48,6 +61,7 @@ async def init_db() -> None:
|
|
| 48 |
pool = await get_pool()
|
| 49 |
async with pool.acquire() as conn:
|
| 50 |
await conn.execute(SCHEMA_SQL)
|
|
|
|
| 51 |
|
| 52 |
|
| 53 |
async def close_db() -> None:
|
|
@@ -95,7 +109,7 @@ async def mark_used(account_id: int) -> None:
|
|
| 95 |
pool = await get_pool()
|
| 96 |
async with pool.acquire() as conn:
|
| 97 |
await conn.execute(
|
| 98 |
-
"UPDATE emergent_accounts SET last_used = NOW() WHERE id = $1",
|
| 99 |
account_id,
|
| 100 |
)
|
| 101 |
|
|
|
|
| 22 |
refresh_token TEXT DEFAULT '',
|
| 23 |
user_id TEXT DEFAULT '',
|
| 24 |
balance REAL DEFAULT 0,
|
| 25 |
+
use_count INTEGER DEFAULT 0,
|
| 26 |
is_active BOOLEAN DEFAULT TRUE,
|
| 27 |
last_used TIMESTAMPTZ,
|
| 28 |
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
|
|
| 32 |
CREATE INDEX IF NOT EXISTS idx_emergent_active ON emergent_accounts (is_active) WHERE is_active = TRUE;
|
| 33 |
"""
|
| 34 |
|
| 35 |
+
MIGRATION_SQL = """
|
| 36 |
+
DO $$
|
| 37 |
+
BEGIN
|
| 38 |
+
IF NOT EXISTS (
|
| 39 |
+
SELECT 1 FROM information_schema.columns
|
| 40 |
+
WHERE table_name = 'emergent_accounts' AND column_name = 'use_count'
|
| 41 |
+
) THEN
|
| 42 |
+
ALTER TABLE emergent_accounts ADD COLUMN use_count INTEGER DEFAULT 0;
|
| 43 |
+
END IF;
|
| 44 |
+
END $$;
|
| 45 |
+
"""
|
| 46 |
+
|
| 47 |
|
| 48 |
async def get_pool() -> asyncpg.Pool:
|
| 49 |
global _pool
|
|
|
|
| 61 |
pool = await get_pool()
|
| 62 |
async with pool.acquire() as conn:
|
| 63 |
await conn.execute(SCHEMA_SQL)
|
| 64 |
+
await conn.execute(MIGRATION_SQL)
|
| 65 |
|
| 66 |
|
| 67 |
async def close_db() -> None:
|
|
|
|
| 109 |
pool = await get_pool()
|
| 110 |
async with pool.acquire() as conn:
|
| 111 |
await conn.execute(
|
| 112 |
+
"UPDATE emergent_accounts SET last_used = NOW(), use_count = COALESCE(use_count, 0) + 1 WHERE id = $1",
|
| 113 |
account_id,
|
| 114 |
)
|
| 115 |
|
emergent2api/models.py
CHANGED
|
@@ -12,17 +12,42 @@ from pydantic import BaseModel, Field
|
|
| 12 |
# ---------------------------------------------------------------------------
|
| 13 |
|
| 14 |
MODEL_MAP = {
|
|
|
|
| 15 |
"claude-opus-4-6": "claude-opus-4-6",
|
| 16 |
"claude-opus-4.6": "claude-opus-4-6",
|
|
|
|
| 17 |
"claude-sonnet-4-5": "claude-sonnet-4-5",
|
| 18 |
"claude-sonnet-4.5": "claude-sonnet-4-5",
|
| 19 |
"claude-sonnet-4-5-thinking": "claude-sonnet-4-5",
|
| 20 |
"claude-sonnet-4.5-thinking": "claude-sonnet-4-5",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
}
|
| 22 |
|
| 23 |
AVAILABLE_MODELS = [
|
| 24 |
-
{"id":
|
| 25 |
-
|
|
|
|
|
|
|
| 26 |
{"id": "claude-sonnet-4-5-thinking", "object": "model", "created": 1709251200, "owned_by": "emergent"},
|
| 27 |
]
|
| 28 |
|
|
@@ -31,8 +56,6 @@ def resolve_model(model: str) -> tuple[str, bool]:
|
|
| 31 |
"""Resolve user model name to (emergent_model, thinking_enabled)."""
|
| 32 |
thinking = "thinking" in model.lower()
|
| 33 |
emergent_model = MODEL_MAP.get(model, model)
|
| 34 |
-
if emergent_model not in ("claude-opus-4-6", "claude-sonnet-4-5"):
|
| 35 |
-
emergent_model = "claude-sonnet-4-5"
|
| 36 |
return emergent_model, thinking
|
| 37 |
|
| 38 |
|
|
|
|
| 12 |
# ---------------------------------------------------------------------------
|
| 13 |
|
| 14 |
MODEL_MAP = {
|
| 15 |
+
# Claude
|
| 16 |
"claude-opus-4-6": "claude-opus-4-6",
|
| 17 |
"claude-opus-4.6": "claude-opus-4-6",
|
| 18 |
+
"claude-opus-4-6-thinking": "claude-opus-4-6",
|
| 19 |
"claude-sonnet-4-5": "claude-sonnet-4-5",
|
| 20 |
"claude-sonnet-4.5": "claude-sonnet-4-5",
|
| 21 |
"claude-sonnet-4-5-thinking": "claude-sonnet-4-5",
|
| 22 |
"claude-sonnet-4.5-thinking": "claude-sonnet-4-5",
|
| 23 |
+
"claude-haiku-3.5": "claude-haiku-3.5",
|
| 24 |
+
"claude-haiku-3-5": "claude-haiku-3.5",
|
| 25 |
+
# OpenAI
|
| 26 |
+
"gpt-4o": "gpt-4o",
|
| 27 |
+
"gpt-4.1": "gpt-4.1",
|
| 28 |
+
"gpt-4.5": "gpt-4.5",
|
| 29 |
+
"o3": "o3",
|
| 30 |
+
"o4-mini": "o4-mini",
|
| 31 |
+
# Google
|
| 32 |
+
"gemini-2.5-pro": "gemini-2.5-pro",
|
| 33 |
+
"gemini-2.5-flash": "gemini-2.5-flash",
|
| 34 |
+
# Others
|
| 35 |
+
"deepseek-r1": "deepseek-r1",
|
| 36 |
+
"grok-3": "grok-3",
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
KNOWN_MODELS = {
|
| 40 |
+
"claude-opus-4-6", "claude-sonnet-4-5", "claude-haiku-3.5",
|
| 41 |
+
"gpt-4o", "gpt-4.1", "gpt-4.5", "o3", "o4-mini",
|
| 42 |
+
"gemini-2.5-pro", "gemini-2.5-flash",
|
| 43 |
+
"deepseek-r1", "grok-3",
|
| 44 |
}
|
| 45 |
|
| 46 |
AVAILABLE_MODELS = [
|
| 47 |
+
{"id": m, "object": "model", "created": 1709251200, "owned_by": "emergent"}
|
| 48 |
+
for m in sorted(KNOWN_MODELS)
|
| 49 |
+
] + [
|
| 50 |
+
{"id": "claude-opus-4-6-thinking", "object": "model", "created": 1709251200, "owned_by": "emergent"},
|
| 51 |
{"id": "claude-sonnet-4-5-thinking", "object": "model", "created": 1709251200, "owned_by": "emergent"},
|
| 52 |
]
|
| 53 |
|
|
|
|
| 56 |
"""Resolve user model name to (emergent_model, thinking_enabled)."""
|
| 57 |
thinking = "thinking" in model.lower()
|
| 58 |
emergent_model = MODEL_MAP.get(model, model)
|
|
|
|
|
|
|
| 59 |
return emergent_model, thinking
|
| 60 |
|
| 61 |
|
emergent2api/routes/admin.py
CHANGED
|
@@ -88,6 +88,7 @@ async def list_tokens(request: Request):
|
|
| 88 |
"id": a["id"],
|
| 89 |
"email": a["email"],
|
| 90 |
"balance": a["balance"],
|
|
|
|
| 91 |
"is_active": a["is_active"],
|
| 92 |
"last_used": a["last_used"].isoformat() if a["last_used"] else None,
|
| 93 |
"created_at": a["created_at"].isoformat() if a["created_at"] else None,
|
|
|
|
| 88 |
"id": a["id"],
|
| 89 |
"email": a["email"],
|
| 90 |
"balance": a["balance"],
|
| 91 |
+
"use_count": a.get("use_count", 0) or 0,
|
| 92 |
"is_active": a["is_active"],
|
| 93 |
"last_used": a["last_used"].isoformat() if a["last_used"] else None,
|
| 94 |
"created_at": a["created_at"].isoformat() if a["created_at"] else None,
|
emergent2api/static/admin/index.html
CHANGED
|
@@ -13,6 +13,7 @@
|
|
| 13 |
--accent:#c97a47;--accent2:#db914f;
|
| 14 |
--green:#34d399;--green-bg:rgba(52,211,153,.1);
|
| 15 |
--red:#f87171;--red-bg:rgba(248,113,113,.1);
|
|
|
|
| 16 |
--blue:#60a5fa;
|
| 17 |
--radius:8px;--mono:'JetBrains Mono',monospace;--sans:'DM Sans',system-ui,sans-serif;
|
| 18 |
}
|
|
@@ -32,9 +33,13 @@ body{font-family:var(--sans);background:var(--bg);color:var(--text);font-size:14
|
|
| 32 |
.login-logo span{font-size:20px;font-weight:700;letter-spacing:-.3px}
|
| 33 |
.login-sub{color:var(--text3);font-size:13px;margin-bottom:32px}
|
| 34 |
.login-label{display:block;font-size:12px;font-weight:600;color:var(--text2);margin-bottom:6px;text-transform:uppercase;letter-spacing:.5px}
|
| 35 |
-
.
|
| 36 |
-
.
|
| 37 |
-
.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
.login-btn{width:100%;margin-top:20px;padding:11px;background:var(--accent);color:#fff;border:none;border-radius:var(--radius);font-size:14px;font-weight:600;font-family:var(--sans);cursor:pointer;transition:background .15s}
|
| 39 |
.login-btn:hover{background:var(--accent2)}
|
| 40 |
.login-err{color:var(--red);font-size:12px;text-align:center;margin-top:12px;display:none}
|
|
@@ -54,7 +59,6 @@ body{font-family:var(--sans);background:var(--bg);color:var(--text);font-size:14
|
|
| 54 |
.main{max-width:1080px;margin:0 auto;padding:28px 24px}
|
| 55 |
.page{display:none}.page.on{display:block}
|
| 56 |
|
| 57 |
-
/* ═══ SECTION HEADER ═══ */
|
| 58 |
.sec-head{display:flex;align-items:baseline;gap:12px;margin-bottom:20px}
|
| 59 |
.sec-title{font-size:20px;font-weight:700;letter-spacing:-.3px}
|
| 60 |
.sec-sub{font-size:13px;color:var(--text3)}
|
|
@@ -64,6 +68,7 @@ body{font-family:var(--sans);background:var(--bg);color:var(--text);font-size:14
|
|
| 64 |
.st{background:var(--bg2);border:1px solid var(--border);border-radius:var(--radius);padding:16px 18px}
|
| 65 |
.st-v{font-size:28px;font-weight:700;font-family:var(--mono);letter-spacing:-.5px}
|
| 66 |
.st-v.g{color:var(--green)}.st-v.r{color:var(--red)}.st-v.o{color:var(--accent)}
|
|
|
|
| 67 |
.st-l{font-size:11px;color:var(--text3);margin-top:4px;text-transform:uppercase;letter-spacing:.5px}
|
| 68 |
|
| 69 |
/* ═══ TOOLBAR ═══ */
|
|
@@ -81,10 +86,12 @@ body{font-family:var(--sans);background:var(--bg);color:var(--text);font-size:14
|
|
| 81 |
.tbtn.red:hover{background:var(--red-bg)}
|
| 82 |
.tbtn.green{background:transparent;border-color:var(--green);color:var(--green)}
|
| 83 |
.tbtn.green:hover{background:var(--green-bg)}
|
|
|
|
|
|
|
| 84 |
|
| 85 |
/* ═══ TABLE ═══ */
|
| 86 |
.tbl-wrap{background:var(--bg2);border:1px solid var(--border);border-radius:var(--radius);overflow-x:auto}
|
| 87 |
-
table{width:100%;border-collapse:collapse;min-width:
|
| 88 |
th{text-align:left;padding:10px 14px;font-size:11px;font-weight:600;color:var(--text3);text-transform:uppercase;letter-spacing:.5px;border-bottom:1px solid var(--border);background:var(--bg3)}
|
| 89 |
td{padding:9px 14px;font-size:13px;border-bottom:1px solid var(--border)}
|
| 90 |
tr:last-child td{border-bottom:none}
|
|
@@ -125,6 +132,7 @@ tr:hover td{background:rgba(255,255,255,.02)}
|
|
| 125 |
.fld .hint{font-size:11px;color:var(--text3);margin-top:4px}
|
| 126 |
.fld-row{display:flex;gap:10px;align-items:end}
|
| 127 |
.fld-row .fld{flex:1}
|
|
|
|
| 128 |
|
| 129 |
/* ═══ DOCS ═══ */
|
| 130 |
.doc{background:var(--bg2);border:1px solid var(--border);border-radius:var(--radius);padding:24px;margin-bottom:14px}
|
|
@@ -135,6 +143,11 @@ tr:hover td{background:rgba(255,255,255,.02)}
|
|
| 135 |
.doc th{text-align:left;padding:7px 12px;font-size:11px;font-weight:600;color:var(--text3);text-transform:uppercase;letter-spacing:.4px;border-bottom:1px solid var(--border);background:var(--bg3)}
|
| 136 |
.doc td{padding:7px 12px;border-bottom:1px solid var(--border);color:var(--text2)}
|
| 137 |
.doc code{background:var(--bg);padding:2px 6px;border-radius:3px;font-family:var(--mono);font-size:12px;color:var(--accent)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
/* ═══ TOAST ═══ */
|
| 140 |
.toast{position:fixed;bottom:20px;right:20px;background:var(--surface2);border:1px solid var(--border2);color:var(--text);padding:10px 18px;border-radius:8px;font-size:13px;z-index:300;opacity:0;transition:opacity .2s;pointer-events:none}
|
|
@@ -153,7 +166,12 @@ tr:hover td{background:rgba(255,255,255,.02)}
|
|
| 153 |
</div>
|
| 154 |
<div class="login-sub">Admin Console</div>
|
| 155 |
<label class="login-label">Password</label>
|
| 156 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
<button class="login-btn" onclick="doLogin()">Sign In</button>
|
| 158 |
<div class="login-err" id="login-err">Invalid password</div>
|
| 159 |
</div>
|
|
@@ -192,12 +210,13 @@ tr:hover td{background:rgba(255,255,255,.02)}
|
|
| 192 |
<button class="tbtn" onclick="openImport()">↑ 导入</button>
|
| 193 |
<button class="tbtn" onclick="doExport()">↓ 导出</button>
|
| 194 |
<button class="tbtn green" onclick="batchOp('test')">⟳ 测试</button>
|
|
|
|
| 195 |
<button class="tbtn red" onclick="batchOp('delete')">✕ 删除</button>
|
| 196 |
</div>
|
| 197 |
<div class="tbl-wrap">
|
| 198 |
<table><thead><tr>
|
| 199 |
<th style="width:36px"><input type="checkbox" class="chk" id="chk-all" onchange="toggleAll(this.checked)"></th>
|
| 200 |
-
<th>Email</th><th>状态</th><th>
|
| 201 |
</tr></thead><tbody id="tbody"></tbody></table>
|
| 202 |
<div class="pager" id="pager"></div>
|
| 203 |
</div>
|
|
@@ -220,7 +239,16 @@ tr:hover td{background:rgba(255,255,255,.02)}
|
|
| 220 |
</div>
|
| 221 |
<div class="card">
|
| 222 |
<h3>Admin</h3>
|
| 223 |
-
<div class="fld">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
</div>
|
| 225 |
<div style="display:flex;gap:8px;justify-content:flex-end">
|
| 226 |
<button class="tbtn" onclick="loadConfig()">重置</button>
|
|
@@ -233,10 +261,21 @@ tr:hover td{background:rgba(255,255,255,.02)}
|
|
| 233 |
<div class="sec-head"><span class="sec-title">使用文档</span><span class="sec-sub">API 端点与接入指南</span></div>
|
| 234 |
<div class="doc">
|
| 235 |
<h3>可用模型</h3>
|
| 236 |
-
<table><tr><th>Model ID</th><th>Description</th></tr>
|
| 237 |
-
<tr><td><code>claude-opus-4-6</code></td><td>Claude Opus 4.6 — full, uncapped</td></tr>
|
| 238 |
-
<tr><td><code>claude-
|
| 239 |
-
<tr><td><code>claude-sonnet-4-5
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
</table>
|
| 241 |
</div>
|
| 242 |
<div class="doc">
|
|
@@ -294,8 +333,20 @@ for chunk in client.chat.completions.create(
|
|
| 294 |
const A='/v1/admin';
|
| 295 |
let tokens=[],filter='all',sel=new Set(),pg=1,PS=50;
|
| 296 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 297 |
async function api(p,o={}){const r=await fetch(A+p,o);if(r.status===401){showLogin();return null}return r}
|
| 298 |
-
function toast(m,d=2500){const t=
|
| 299 |
function $(id){return document.getElementById(id)}
|
| 300 |
function showLogin(){$('view-login').style.display='';$('view-main').style.display='none'}
|
| 301 |
function showMain(){$('view-login').style.display='none';$('view-main').style.display=''}
|
|
@@ -304,7 +355,7 @@ $('pwd').addEventListener('keydown',e=>{if(e.key==='Enter')doLogin()});
|
|
| 304 |
|
| 305 |
async function doLogin(){
|
| 306 |
const r=await fetch(A+'/login',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({password:$('pwd').value})});
|
| 307 |
-
if(r.ok){showMain();load();loadConfig()}else
|
| 308 |
}
|
| 309 |
async function doLogout(){await api('/logout',{method:'POST'});showLogin()}
|
| 310 |
async function checkAuth(){const r=await fetch(A+'/verify');if(r.ok){showMain();load();loadConfig()}}
|
|
@@ -312,7 +363,7 @@ checkAuth();
|
|
| 312 |
|
| 313 |
function showPage(p){
|
| 314 |
document.querySelectorAll('.page').forEach(e=>e.classList.remove('on'));
|
| 315 |
-
$(
|
| 316 |
document.querySelectorAll('.tab').forEach(e=>e.classList.toggle('on',e.dataset.p===p));
|
| 317 |
}
|
| 318 |
|
|
@@ -338,11 +389,11 @@ function render(){
|
|
| 338 |
<td><input type="checkbox" class="chk" data-id="${t.id}" ${sel.has(t.id)?'checked':''} onchange="tSel(${t.id},this.checked)"></td>
|
| 339 |
<td class="mono" title="${e}">${sh}</td>
|
| 340 |
<td><span class="badge ${t.is_active?'badge-g':'badge-r'}">${t.is_active?'active':'inactive'}</span></td>
|
| 341 |
-
<td style="color:var(--text2)">$
|
| 342 |
<td style="color:var(--text3);font-size:12px">${t.last_used?new Date(t.last_used).toLocaleString('zh-CN'):'-'}</td>
|
| 343 |
<td class="ops">
|
| 344 |
<button class="op" title="Refresh JWT" onclick="rOne(${t.id})">↻</button>
|
| 345 |
-
<button class="op" title="${t.is_active?'
|
| 346 |
<button class="op del" title="Delete" onclick="dOne(${t.id})">✕</button>
|
| 347 |
</td></tr>`}).join('');
|
| 348 |
$('pager').innerHTML=ls.length>PS?`<button ${pg<=1?'disabled':''} onclick="goPg(${pg-1})">‹ Prev</button><span>Page ${pg} / ${tp} · ${ls.length} total</span><button ${pg>=tp?'disabled':''} onclick="goPg(${pg+1})">Next ›</button>`:'';
|
|
@@ -358,19 +409,26 @@ async function dOne(id){if(!confirm('Delete this token?'))return;await api('/tok
|
|
| 358 |
async function rOne(id){toast('Refreshing…');const r=await api('/tokens/refresh',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({ids:[id]})});if(r){const d=await r.json();toast(d.refreshed?'Refreshed':'Failed')}load()}
|
| 359 |
|
| 360 |
async function batchOp(action){
|
| 361 |
-
const ids=[...sel];if(!ids.length){toast('
|
| 362 |
-
if(action==='delete'&&!confirm(`
|
| 363 |
-
toast(`
|
| 364 |
const r=await api(`/tokens/${action}`,{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({ids})});
|
| 365 |
if(r){const d=await r.json();toast(JSON.stringify(d))}sel.clear();load();
|
| 366 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 367 |
|
| 368 |
function openImport(){$('dlg-import').classList.add('open')}
|
| 369 |
function closeImport(){$('dlg-import').classList.remove('open')}
|
| 370 |
async function doImport(){
|
| 371 |
const t=$('import-text').value.trim();if(!t){toast('Paste JSONL data');return}
|
| 372 |
const r=await api('/tokens/import',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({jsonl:t})});
|
| 373 |
-
if(r){const d=await r.json();toast(`
|
| 374 |
}
|
| 375 |
async function doExport(){const r=await api('/tokens/export');if(!r)return;const b=await r.blob();const a=document.createElement('a');a.href=URL.createObjectURL(b);a.download='emergent_tokens.zip';a.click()}
|
| 376 |
|
|
@@ -382,7 +440,7 @@ async function loadConfig(){
|
|
| 382 |
async function saveConfig(){
|
| 383 |
const b={api_key:$('cfg-api_key').value,backend:$('cfg-backend').value,proxy:$('cfg-proxy').value,admin_password:$('cfg-admin_password').value};
|
| 384 |
const r=await api('/config',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(b)});
|
| 385 |
-
if(r){const d=await r.json();toast(`
|
| 386 |
}
|
| 387 |
async function genKey(){
|
| 388 |
const r=await api('/config/generate-key',{method:'POST'});
|
|
|
|
| 13 |
--accent:#c97a47;--accent2:#db914f;
|
| 14 |
--green:#34d399;--green-bg:rgba(52,211,153,.1);
|
| 15 |
--red:#f87171;--red-bg:rgba(248,113,113,.1);
|
| 16 |
+
--yellow:#fbbf24;--yellow-bg:rgba(251,191,36,.1);
|
| 17 |
--blue:#60a5fa;
|
| 18 |
--radius:8px;--mono:'JetBrains Mono',monospace;--sans:'DM Sans',system-ui,sans-serif;
|
| 19 |
}
|
|
|
|
| 33 |
.login-logo span{font-size:20px;font-weight:700;letter-spacing:-.3px}
|
| 34 |
.login-sub{color:var(--text3);font-size:13px;margin-bottom:32px}
|
| 35 |
.login-label{display:block;font-size:12px;font-weight:600;color:var(--text2);margin-bottom:6px;text-transform:uppercase;letter-spacing:.5px}
|
| 36 |
+
.pwd-wrap{position:relative}
|
| 37 |
+
.pwd-wrap input{width:100%;padding:11px 40px 11px 14px;background:var(--bg3);border:1px solid var(--border);border-radius:var(--radius);color:var(--text);font-size:14px;font-family:var(--sans);outline:none;transition:border .2s}
|
| 38 |
+
.pwd-wrap input:focus{border-color:var(--accent)}
|
| 39 |
+
.pwd-wrap input::placeholder{color:var(--text3)}
|
| 40 |
+
.eye-btn{position:absolute;right:10px;top:50%;transform:translateY(-50%);background:none;border:none;color:var(--text3);cursor:pointer;padding:4px;display:flex;align-items:center;justify-content:center}
|
| 41 |
+
.eye-btn:hover{color:var(--text2)}
|
| 42 |
+
.eye-btn svg{width:18px;height:18px}
|
| 43 |
.login-btn{width:100%;margin-top:20px;padding:11px;background:var(--accent);color:#fff;border:none;border-radius:var(--radius);font-size:14px;font-weight:600;font-family:var(--sans);cursor:pointer;transition:background .15s}
|
| 44 |
.login-btn:hover{background:var(--accent2)}
|
| 45 |
.login-err{color:var(--red);font-size:12px;text-align:center;margin-top:12px;display:none}
|
|
|
|
| 59 |
.main{max-width:1080px;margin:0 auto;padding:28px 24px}
|
| 60 |
.page{display:none}.page.on{display:block}
|
| 61 |
|
|
|
|
| 62 |
.sec-head{display:flex;align-items:baseline;gap:12px;margin-bottom:20px}
|
| 63 |
.sec-title{font-size:20px;font-weight:700;letter-spacing:-.3px}
|
| 64 |
.sec-sub{font-size:13px;color:var(--text3)}
|
|
|
|
| 68 |
.st{background:var(--bg2);border:1px solid var(--border);border-radius:var(--radius);padding:16px 18px}
|
| 69 |
.st-v{font-size:28px;font-weight:700;font-family:var(--mono);letter-spacing:-.5px}
|
| 70 |
.st-v.g{color:var(--green)}.st-v.r{color:var(--red)}.st-v.o{color:var(--accent)}
|
| 71 |
+
|
| 72 |
.st-l{font-size:11px;color:var(--text3);margin-top:4px;text-transform:uppercase;letter-spacing:.5px}
|
| 73 |
|
| 74 |
/* ═══ TOOLBAR ═══ */
|
|
|
|
| 86 |
.tbtn.red:hover{background:var(--red-bg)}
|
| 87 |
.tbtn.green{background:transparent;border-color:var(--green);color:var(--green)}
|
| 88 |
.tbtn.green:hover{background:var(--green-bg)}
|
| 89 |
+
.tbtn.yellow{background:transparent;border-color:var(--yellow);color:var(--yellow)}
|
| 90 |
+
.tbtn.yellow:hover{background:var(--yellow-bg)}
|
| 91 |
|
| 92 |
/* ═══ TABLE ═══ */
|
| 93 |
.tbl-wrap{background:var(--bg2);border:1px solid var(--border);border-radius:var(--radius);overflow-x:auto}
|
| 94 |
+
table{width:100%;border-collapse:collapse;min-width:700px}
|
| 95 |
th{text-align:left;padding:10px 14px;font-size:11px;font-weight:600;color:var(--text3);text-transform:uppercase;letter-spacing:.5px;border-bottom:1px solid var(--border);background:var(--bg3)}
|
| 96 |
td{padding:9px 14px;font-size:13px;border-bottom:1px solid var(--border)}
|
| 97 |
tr:last-child td{border-bottom:none}
|
|
|
|
| 132 |
.fld .hint{font-size:11px;color:var(--text3);margin-top:4px}
|
| 133 |
.fld-row{display:flex;gap:10px;align-items:end}
|
| 134 |
.fld-row .fld{flex:1}
|
| 135 |
+
.fld .pwd-wrap input{padding-right:40px}
|
| 136 |
|
| 137 |
/* ═══ DOCS ═══ */
|
| 138 |
.doc{background:var(--bg2);border:1px solid var(--border);border-radius:var(--radius);padding:24px;margin-bottom:14px}
|
|
|
|
| 143 |
.doc th{text-align:left;padding:7px 12px;font-size:11px;font-weight:600;color:var(--text3);text-transform:uppercase;letter-spacing:.4px;border-bottom:1px solid var(--border);background:var(--bg3)}
|
| 144 |
.doc td{padding:7px 12px;border-bottom:1px solid var(--border);color:var(--text2)}
|
| 145 |
.doc code{background:var(--bg);padding:2px 6px;border-radius:3px;font-family:var(--mono);font-size:12px;color:var(--accent)}
|
| 146 |
+
.doc .tag{display:inline-block;padding:1px 6px;border-radius:3px;font-size:10px;font-weight:600;font-family:var(--mono);margin-left:4px}
|
| 147 |
+
.doc .tag-c{background:rgba(201,122,71,.15);color:var(--accent)}
|
| 148 |
+
.doc .tag-o{background:rgba(96,165,250,.15);color:var(--blue)}
|
| 149 |
+
.doc .tag-g{background:rgba(52,211,153,.15);color:var(--green)}
|
| 150 |
+
.doc .tag-y{background:rgba(251,191,36,.15);color:var(--yellow)}
|
| 151 |
|
| 152 |
/* ═══ TOAST ═══ */
|
| 153 |
.toast{position:fixed;bottom:20px;right:20px;background:var(--surface2);border:1px solid var(--border2);color:var(--text);padding:10px 18px;border-radius:8px;font-size:13px;z-index:300;opacity:0;transition:opacity .2s;pointer-events:none}
|
|
|
|
| 166 |
</div>
|
| 167 |
<div class="login-sub">Admin Console</div>
|
| 168 |
<label class="login-label">Password</label>
|
| 169 |
+
<div class="pwd-wrap">
|
| 170 |
+
<input type="password" id="pwd" placeholder="Enter admin password" autofocus>
|
| 171 |
+
<button class="eye-btn" onclick="togglePwd('pwd')" type="button" tabindex="-1">
|
| 172 |
+
<svg id="eye-pwd" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>
|
| 173 |
+
</button>
|
| 174 |
+
</div>
|
| 175 |
<button class="login-btn" onclick="doLogin()">Sign In</button>
|
| 176 |
<div class="login-err" id="login-err">Invalid password</div>
|
| 177 |
</div>
|
|
|
|
| 210 |
<button class="tbtn" onclick="openImport()">↑ 导入</button>
|
| 211 |
<button class="tbtn" onclick="doExport()">↓ 导出</button>
|
| 212 |
<button class="tbtn green" onclick="batchOp('test')">⟳ 测试</button>
|
| 213 |
+
<button class="tbtn yellow" onclick="batchDeactivate()">⏸ 停用</button>
|
| 214 |
<button class="tbtn red" onclick="batchOp('delete')">✕ 删除</button>
|
| 215 |
</div>
|
| 216 |
<div class="tbl-wrap">
|
| 217 |
<table><thead><tr>
|
| 218 |
<th style="width:36px"><input type="checkbox" class="chk" id="chk-all" onchange="toggleAll(this.checked)"></th>
|
| 219 |
+
<th>Email</th><th>状态</th><th>调用次数</th><th>最后使用</th><th>操作</th>
|
| 220 |
</tr></thead><tbody id="tbody"></tbody></table>
|
| 221 |
<div class="pager" id="pager"></div>
|
| 222 |
</div>
|
|
|
|
| 239 |
</div>
|
| 240 |
<div class="card">
|
| 241 |
<h3>Admin</h3>
|
| 242 |
+
<div class="fld">
|
| 243 |
+
<label>Password</label>
|
| 244 |
+
<div class="pwd-wrap">
|
| 245 |
+
<input id="cfg-admin_password" type="password">
|
| 246 |
+
<button class="eye-btn" onclick="togglePwd('cfg-admin_password')" type="button" tabindex="-1">
|
| 247 |
+
<svg id="eye-cfg-admin_password" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>
|
| 248 |
+
</button>
|
| 249 |
+
</div>
|
| 250 |
+
<div class="hint">修改后点击保存,密码将持久化到数据库</div>
|
| 251 |
+
</div>
|
| 252 |
</div>
|
| 253 |
<div style="display:flex;gap:8px;justify-content:flex-end">
|
| 254 |
<button class="tbtn" onclick="loadConfig()">重置</button>
|
|
|
|
| 261 |
<div class="sec-head"><span class="sec-title">使用文档</span><span class="sec-sub">API 端点与接入指南</span></div>
|
| 262 |
<div class="doc">
|
| 263 |
<h3>可用模型</h3>
|
| 264 |
+
<table><tr><th>Model ID</th><th>Provider</th><th>Description</th></tr>
|
| 265 |
+
<tr><td><code>claude-opus-4-6</code></td><td>Anthropic <span class="tag tag-c">Claude</span></td><td>Claude Opus 4.6 — full, uncapped</td></tr>
|
| 266 |
+
<tr><td><code>claude-opus-4-6-thinking</code></td><td>Anthropic <span class="tag tag-c">Claude</span></td><td>Claude Opus 4.6 — extended thinking</td></tr>
|
| 267 |
+
<tr><td><code>claude-sonnet-4-5</code></td><td>Anthropic <span class="tag tag-c">Claude</span></td><td>Claude Sonnet 4.5</td></tr>
|
| 268 |
+
<tr><td><code>claude-sonnet-4-5-thinking</code></td><td>Anthropic <span class="tag tag-c">Claude</span></td><td>Claude Sonnet 4.5 — extended thinking</td></tr>
|
| 269 |
+
<tr><td><code>claude-haiku-3.5</code></td><td>Anthropic <span class="tag tag-c">Claude</span></td><td>Claude Haiku 3.5 — fast</td></tr>
|
| 270 |
+
<tr><td><code>gpt-4o</code></td><td>OpenAI <span class="tag tag-o">GPT</span></td><td>GPT-4o</td></tr>
|
| 271 |
+
<tr><td><code>gpt-4.1</code></td><td>OpenAI <span class="tag tag-o">GPT</span></td><td>GPT-4.1</td></tr>
|
| 272 |
+
<tr><td><code>gpt-4.5</code></td><td>OpenAI <span class="tag tag-o">GPT</span></td><td>GPT-4.5</td></tr>
|
| 273 |
+
<tr><td><code>o3</code></td><td>OpenAI <span class="tag tag-o">GPT</span></td><td>O3 reasoning model</td></tr>
|
| 274 |
+
<tr><td><code>o4-mini</code></td><td>OpenAI <span class="tag tag-o">GPT</span></td><td>O4-mini reasoning model</td></tr>
|
| 275 |
+
<tr><td><code>gemini-2.5-pro</code></td><td>Google <span class="tag tag-g">Gemini</span></td><td>Gemini 2.5 Pro</td></tr>
|
| 276 |
+
<tr><td><code>gemini-2.5-flash</code></td><td>Google <span class="tag tag-g">Gemini</span></td><td>Gemini 2.5 Flash</td></tr>
|
| 277 |
+
<tr><td><code>deepseek-r1</code></td><td>DeepSeek <span class="tag tag-y">DS</span></td><td>DeepSeek R1 reasoning</td></tr>
|
| 278 |
+
<tr><td><code>grok-3</code></td><td>xAI <span class="tag tag-y">Grok</span></td><td>Grok 3</td></tr>
|
| 279 |
</table>
|
| 280 |
</div>
|
| 281 |
<div class="doc">
|
|
|
|
| 333 |
const A='/v1/admin';
|
| 334 |
let tokens=[],filter='all',sel=new Set(),pg=1,PS=50;
|
| 335 |
|
| 336 |
+
const EYE_OPEN='<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/>';
|
| 337 |
+
const EYE_SHUT='<path d="M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94"/><path d="M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19"/><path d="M14.12 14.12a3 3 0 1 1-4.24-4.24"/><line x1="1" y1="1" x2="23" y2="23"/>';
|
| 338 |
+
|
| 339 |
+
function togglePwd(id){
|
| 340 |
+
const inp=document.getElementById(id);
|
| 341 |
+
const svg=document.getElementById('eye-'+id);
|
| 342 |
+
if(!inp||!svg)return;
|
| 343 |
+
const show=inp.type==='password';
|
| 344 |
+
inp.type=show?'text':'password';
|
| 345 |
+
svg.innerHTML=show?EYE_SHUT:EYE_OPEN;
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
async function api(p,o={}){const r=await fetch(A+p,o);if(r.status===401){showLogin();return null}return r}
|
| 349 |
+
function toast(m,d=2500){const t=document.getElementById('toast');t.textContent=m;t.classList.add('show');setTimeout(()=>t.classList.remove('show'),d)}
|
| 350 |
function $(id){return document.getElementById(id)}
|
| 351 |
function showLogin(){$('view-login').style.display='';$('view-main').style.display='none'}
|
| 352 |
function showMain(){$('view-login').style.display='none';$('view-main').style.display=''}
|
|
|
|
| 355 |
|
| 356 |
async function doLogin(){
|
| 357 |
const r=await fetch(A+'/login',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({password:$('pwd').value})});
|
| 358 |
+
if(r.ok){showMain();load();loadConfig()}else{$('login-err').style.display='block'}
|
| 359 |
}
|
| 360 |
async function doLogout(){await api('/logout',{method:'POST'});showLogin()}
|
| 361 |
async function checkAuth(){const r=await fetch(A+'/verify');if(r.ok){showMain();load();loadConfig()}}
|
|
|
|
| 363 |
|
| 364 |
function showPage(p){
|
| 365 |
document.querySelectorAll('.page').forEach(e=>e.classList.remove('on'));
|
| 366 |
+
$('p-'+p).classList.add('on');
|
| 367 |
document.querySelectorAll('.tab').forEach(e=>e.classList.toggle('on',e.dataset.p===p));
|
| 368 |
}
|
| 369 |
|
|
|
|
| 389 |
<td><input type="checkbox" class="chk" data-id="${t.id}" ${sel.has(t.id)?'checked':''} onchange="tSel(${t.id},this.checked)"></td>
|
| 390 |
<td class="mono" title="${e}">${sh}</td>
|
| 391 |
<td><span class="badge ${t.is_active?'badge-g':'badge-r'}">${t.is_active?'active':'inactive'}</span></td>
|
| 392 |
+
<td style="color:var(--text2);font-family:var(--mono);font-size:12px">${t.use_count||0}</td>
|
| 393 |
<td style="color:var(--text3);font-size:12px">${t.last_used?new Date(t.last_used).toLocaleString('zh-CN'):'-'}</td>
|
| 394 |
<td class="ops">
|
| 395 |
<button class="op" title="Refresh JWT" onclick="rOne(${t.id})">↻</button>
|
| 396 |
+
<button class="op" title="${t.is_active?'停用':'启用'}" onclick="tOne(${t.id})">⏻</button>
|
| 397 |
<button class="op del" title="Delete" onclick="dOne(${t.id})">✕</button>
|
| 398 |
</td></tr>`}).join('');
|
| 399 |
$('pager').innerHTML=ls.length>PS?`<button ${pg<=1?'disabled':''} onclick="goPg(${pg-1})">‹ Prev</button><span>Page ${pg} / ${tp} · ${ls.length} total</span><button ${pg>=tp?'disabled':''} onclick="goPg(${pg+1})">Next ›</button>`:'';
|
|
|
|
| 409 |
async function rOne(id){toast('Refreshing…');const r=await api('/tokens/refresh',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({ids:[id]})});if(r){const d=await r.json();toast(d.refreshed?'Refreshed':'Failed')}load()}
|
| 410 |
|
| 411 |
async function batchOp(action){
|
| 412 |
+
const ids=[...sel];if(!ids.length){toast('请先选择 Token');return}
|
| 413 |
+
if(action==='delete'&&!confirm(`确定删除 ${ids.length} 个 Token?`))return;
|
| 414 |
+
toast(`处理中 (${ids.length})…`);
|
| 415 |
const r=await api(`/tokens/${action}`,{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({ids})});
|
| 416 |
if(r){const d=await r.json();toast(JSON.stringify(d))}sel.clear();load();
|
| 417 |
}
|
| 418 |
+
async function batchDeactivate(){
|
| 419 |
+
const ids=[...sel];if(!ids.length){toast('请先选择 Token');return}
|
| 420 |
+
if(!confirm(`停用 ${ids.length} 个 Token?停用后不会参与轮询`))return;
|
| 421 |
+
toast(`停用中 (${ids.length})…`);
|
| 422 |
+
const r=await api('/tokens/toggle',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({ids,active:false})});
|
| 423 |
+
if(r){const d=await r.json();toast(`已停用 ${d.updated} 个`)}sel.clear();load();
|
| 424 |
+
}
|
| 425 |
|
| 426 |
function openImport(){$('dlg-import').classList.add('open')}
|
| 427 |
function closeImport(){$('dlg-import').classList.remove('open')}
|
| 428 |
async function doImport(){
|
| 429 |
const t=$('import-text').value.trim();if(!t){toast('Paste JSONL data');return}
|
| 430 |
const r=await api('/tokens/import',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({jsonl:t})});
|
| 431 |
+
if(r){const d=await r.json();toast(`导入 ${d.imported} 个`+(d.errors.length?`,${d.errors.length} 个错误`:''));closeImport();load()}
|
| 432 |
}
|
| 433 |
async function doExport(){const r=await api('/tokens/export');if(!r)return;const b=await r.blob();const a=document.createElement('a');a.href=URL.createObjectURL(b);a.download='emergent_tokens.zip';a.click()}
|
| 434 |
|
|
|
|
| 440 |
async function saveConfig(){
|
| 441 |
const b={api_key:$('cfg-api_key').value,backend:$('cfg-backend').value,proxy:$('cfg-proxy').value,admin_password:$('cfg-admin_password').value};
|
| 442 |
const r=await api('/config',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(b)});
|
| 443 |
+
if(r){const d=await r.json();toast(`已保存: ${d.saved.join(', ')}`)}
|
| 444 |
}
|
| 445 |
async function genKey(){
|
| 446 |
const r=await api('/config/generate-key',{method:'POST'});
|