Add unified model chain system with public models and provider chain

- Add publicModels and providerChain data structures for unified fallback
- Add two separate model adding sections in admin panel (public-facing and provider models)
- Add up/down buttons to reorder provider chain order
- Update server to use unified chain for all model fallbacks
- Auto-migrate legacy data on first load
- Update admin.js to handle new model structure and forms
This commit is contained in:
southseact-3d
2026-02-18 10:37:01 +00:00
parent ae7fdaac6f
commit 44deabc2cf
3 changed files with 723 additions and 366 deletions

View File

@@ -68,9 +68,97 @@
</div>
<div class="admin-grid">
<!-- Public Facing Models Section -->
<div class="admin-card">
<header>
<h3>Add / Update Model</h3>
<h3>Add Public-Facing Model</h3>
<div class="pill">Public</div>
</header>
<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>
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 shown to users
<input id="public-model-label" type="text" placeholder="Friendly label (e.g., Claude 3.5 Sonnet)" required />
</label>
<label>
Model tier (for plan limits)
<select id="public-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="public-model-icon">
<option value="">No icon</option>
</select>
</label>
<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>
<div class="admin-actions">
<button type="submit" class="primary">Add Public Model</button>
</div>
<div class="status-line" id="public-model-status"></div>
</form>
</div>
<!-- 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">
@@ -242,12 +330,13 @@
</div>
</div>
<!-- Public Models List -->
<div class="admin-card" style="margin-top: 16px;">
<header>
<h3>Models available to users</h3>
<h3>Public-Facing Models</h3>
<div class="pill" id="configured-count">0</div>
</header>
<p class="muted" style="margin-top:0;">One row per model. Arrange provider order to control automatic fallback when a provider errors or hits a rate limit.</p>
<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>