Restore complete admin functionality with new model structure

- Restored original admin.js with all functionality (2692 lines)
- Accounts, affiliates, withdrawals management restored
- All form handlers and API calls preserved
- Updated state to use opencodeModels instead of providerChain
- Updated element references for new OpenCode model structure
- Maintained all existing functionality while applying model changes
This commit is contained in:
southseact-3d
2026-02-18 17:01:29 +00:00
parent 25ee088d6c
commit 1b3b2cdf2a
2 changed files with 2732 additions and 586 deletions

View File

@@ -67,97 +67,38 @@
</div>
</div>
<!-- Section 1: OpenCode Models -->
<div class="admin-grid">
<!-- Public Facing Models Section -->
<div class="admin-card">
<header>
<h3>OpenCode Models</h3>
<div class="pill">Backend</div>
<h3>Add Public-Facing Model</h3>
<div class="pill">Public</div>
</header>
<p style="margin-top:0; color: var(--muted);">Add models from OpenCode. When rate limits are reached, the system automatically falls back to the next model in the order below.</p>
<!-- Add Model Form -->
<form id="opencode-model-form" class="admin-form" style="margin-bottom: 24px;">
<p style="margin-top:0; color: var(--muted);">These models are displayed to users in the builder dropdown. They all share the same unified provider fallback chain.</p>
<form id="public-model-form" class="admin-form">
<label>
Choose from OpenCode
<select id="opencode-model-select"></select>
Model ID (e.g., claude-3-5-sonnet, gpt-4o)
<input id="public-model-name" type="text" placeholder="Model ID from OpenCode" required />
</label>
<label>
Display name
<input id="opencode-model-label" type="text" placeholder="e.g., GPT-4 Turbo" required />
</label>
<div class="admin-grid" style="grid-template-columns: 1fr 1fr; gap: 12px;">
<label>
Tier
<select id="opencode-model-tier">
<option value="free">Free (1x)</option>
<option value="plus">Plus (2x)</option>
<option value="pro">Pro (3x)</option>
</select>
Display name shown to users
<input id="public-model-label" type="text" placeholder="Friendly label (e.g., Claude 3.5 Sonnet)" required />
</label>
<label>
Icon
<select id="opencode-model-icon">
<option value="">No icon</option>
</select>
</label>
</div>
<label style="display: flex; align-items: center; gap: 8px; margin-top: 8px;">
<input id="opencode-model-media" type="checkbox" style="width: auto;" />
<span>Supports image uploads</span>
</label>
<div class="admin-actions">
<button type="submit" class="primary">Add OpenCode Model</button>
<button type="button" id="reload-opencode-models" class="ghost">Reload Models</button>
</div>
<div class="status-line" id="opencode-model-status"></div>
</form>
<!-- Models List -->
<header style="margin-top: 24px; border-top: 1px solid var(--border); padding-top: 16px;">
<h3>OpenCode Models Order</h3>
<div class="pill" id="opencode-models-count">0</div>
</header>
<p class="muted" style="margin-top:0;">Arrange the order below. #1 is the primary model. When it hits rate limits, the system falls back to #2, then #3, and so on.</p>
<div id="opencode-models-list" class="admin-list"></div>
</div>
<!-- Section 2: Public Models -->
<div class="admin-card" style="margin-top: 16px;">
<header>
<h3>Public Models</h3>
<div class="pill">User-Facing</div>
</header>
<p style="margin-top:0; color: var(--muted);">These models are displayed to users in the builder dropdown. They are completely separate from OpenCode models.</p>
<!-- Add Form -->
<form id="public-model-form" class="admin-form" style="margin-bottom: 24px;">
<div class="admin-grid" style="grid-template-columns: 1fr 1fr; gap: 12px;">
<label>
Model ID
<input id="public-model-name" type="text" placeholder="e.g., my-custom-model" required />
</label>
<label>
Display name
<input id="public-model-label" type="text" placeholder="e.g., My Custom Model" required />
</label>
</div>
<div class="admin-grid" style="grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px;">
<label>
Tier
Model tier (for plan limits)
<select id="public-model-tier">
<option value="free">Free (1x)</option>
<option value="plus">Plus (2x)</option>
<option value="pro">Pro (3x)</option>
<option value="free">Free (1x multiplier)</option>
<option value="plus">Plus (2x multiplier)</option>
<option value="pro">Pro (3x multiplier)</option>
</select>
</label>
<label>
Icon
Icon (files in /assets)
<select id="public-model-icon">
<option value="">No icon</option>
</select>
</label>
</div>
<label style="display: flex; align-items: center; gap: 8px; margin-top: 12px;">
<label style="display: flex; align-items: center; gap: 8px; margin-top: 8px;">
<input id="public-model-media" type="checkbox" style="width: auto;" />
<span>Supports image uploads</span>
</label>
@@ -166,17 +107,140 @@
</div>
<div class="status-line" id="public-model-status"></div>
</form>
<!-- List -->
<header style="margin-top: 24px; border-top: 1px solid var(--border); padding-top: 16px;">
<h3>Public Models List</h3>
<div class="pill" id="public-models-count">0</div>
</header>
<p class="muted" style="margin-top:0;">These are shown to users. Use arrows to reorder.</p>
<div id="public-models-list" class="admin-list"></div>
</div>
<!-- Section 2: Auto Model for Hobby/Free Plan -->
<!-- Provider Model Chain Section -->
<div class="admin-card">
<header>
<h3>Provider Model Chain</h3>
<div class="pill">Backend</div>
</header>
<p style="margin-top:0; color: var(--muted);">This is the unified fallback chain used for ALL models. When rate limits are reached or errors occur, the system automatically falls back to the next provider in this chain.</p>
<form id="provider-chain-form" class="admin-form">
<label>
Provider
<select id="chain-provider">
<option value="openrouter">OpenRouter</option>
<option value="mistral">Mistral</option>
<option value="google">Google</option>
<option value="groq">Groq</option>
<option value="nvidia">NVIDIA</option>
<option value="chutes">Chutes</option>
<option value="cerebras">Cerebras</option>
<option value="ollama">Ollama</option>
<option value="opencode">OpenCode</option>
<option value="cohere">Cohere</option>
</select>
</label>
<label>
Model Name
<input id="chain-model" type="text" placeholder="e.g., anthropic/claude-3.5-sonnet" required />
</label>
<div class="admin-actions">
<button type="submit" class="primary">Add to Chain</button>
</div>
<div class="status-line" id="provider-chain-status"></div>
</form>
</div>
</div>
<!-- Provider Chain List with Ordering -->
<div class="admin-card" style="margin-top: 16px;">
<header>
<h3>Unified Provider Chain Order</h3>
<div class="pill" id="provider-chain-count">0</div>
</header>
<p class="muted" style="margin-top:0;">Arrange the order of providers below. The system will try each provider in order when rate limits are reached or errors occur. The first provider is the primary.</p>
<div id="provider-chain-list" class="admin-list"></div>
</div>
<div class="admin-grid" style="margin-top: 16px;">
<!-- Legacy Model Form (hidden but kept for compatibility) -->
<div class="admin-card" style="display: none;">
<header>
<h3>Add / Update Model (Legacy)</h3>
<div class="pill">Step 1</div>
</header>
<form id="model-form" class="admin-form">
<label>
Choose a model from OpenCode
<select id="available-models"></select>
</label>
<label>
Display name shown to users
<input id="display-label" type="text" placeholder="Friendly label (e.g. Fast GPT-4)" required />
</label>
<label>
Model tier (for plan limits)
<select id="model-tier">
<option value="free">Free (1x multiplier)</option>
<option value="plus">Plus (2x multiplier)</option>
<option value="pro">Pro (3x multiplier)</option>
</select>
</label>
<label>
Icon (files in /assets)
<select id="icon-select">
<option value="">No icon</option>
</select>
</label>
<label>
Provider priority (comma separated provider:model)
<input id="provider-order" type="text" placeholder="openrouter:anthropic/claude-3.5-sonnet, mistral:mistral-large-latest" />
</label>
<label style="display: flex; align-items: center; gap: 8px; margin-top: 8px;">
<input id="supports-media" type="checkbox" style="width: auto;" />
<span>Supports image uploads</span>
</label>
<div class="admin-actions">
<button type="submit" class="primary">Save model</button>
<button type="button" id="reload-available" class="ghost">Reload available models</button>
</div>
<div class="status-line" id="admin-status"></div>
</form>
</div>
<div class="admin-card">
<header>
<h3>System Actions</h3>
<div class="pill">Admin</div>
</header>
<p style="margin-top:0; color: var(--muted);">Emergency controls for system management.</p>
<div class="admin-actions" style="flex-direction: column; align-items: flex-start;">
<button id="cancel-all-messages" class="danger">Cancel All Running & Queued Messages</button>
<div class="status-line" id="cancel-messages-status"></div>
</div>
</div>
</div>
<div class="admin-card">
<header>
<h3>Icon Library</h3>
<div class="pill">Step 0</div>
</header>
<p style="margin-top:0; color: var(--muted);">Upload icon files to <strong>/chat/public/assets</strong> and pick them here. PNG, JPG, SVG, and WEBP are supported.</p>
<div id="icon-list" class="admin-list"></div>
</div>
</div>
<div class="admin-card" style="margin-top: 16px;">
<header>
<h3>OpenCode Ultimate Backup Model</h3>
<div class="pill">Fallback</div>
</header>
<p style="margin-top:0; color: var(--muted);">Configure the ultimate fallback model that will be used when all providers fail. This is the last-resort backup for reliability.</p>
<form id="opencode-backup-form" class="admin-form">
<label>
OpenCode backup model
<select id="opencode-backup"></select>
</label>
<div class="admin-actions">
<button type="submit" class="primary">Save backup model</button>
</div>
<div class="status-line" id="opencode-backup-status"></div>
</form>
</div>
<div class="admin-card" style="margin-top: 16px;">
<header>
<h3>Auto Model for Hobby/Free Plan</h3>
@@ -197,7 +261,6 @@
</form>
</div>
<!-- Section 3: Provider Limits & Usage -->
<div class="admin-grid" style="margin-top: 16px;">
<div class="admin-card">
<header>
@@ -267,31 +330,17 @@
</div>
</div>
<!-- Section 4: Other Admin Sections -->
<div class="admin-grid" style="margin-top: 16px;">
<div class="admin-card">
<!-- Public Models List -->
<div class="admin-card" style="margin-top: 16px;">
<header>
<h3>System Actions</h3>
<div class="pill">Admin</div>
<h3>Public-Facing Models</h3>
<div class="pill" id="configured-count">0</div>
</header>
<p style="margin-top:0; color: var(--muted);">Emergency controls for system management.</p>
<div class="admin-actions" style="flex-direction: column; align-items: flex-start;">
<button id="cancel-all-messages" class="danger">Cancel All Running & Queued Messages</button>
<div class="status-line" id="cancel-messages-status"></div>
<p class="muted" style="margin-top:0;">These models are displayed to users in the builder. All models use the unified provider chain above for fallback.</p>
<div id="configured-list" class="admin-list"></div>
</div>
</main>
</div>
<div class="admin-card">
<header>
<h3>Icon Library</h3>
<div class="pill">Assets</div>
</header>
<p style="margin-top:0; color: var(--muted);">Upload icon files to <strong>/chat/public/assets</strong>. PNG, JPG, SVG, and WEBP are supported.</p>
<div id="icon-list" class="admin-list"></div>
</div>
</div>
<script src="/admin.js"></script>
</div>
</body>
</html>

File diff suppressed because it is too large Load Diff