Add OpenCode Zen support, model health/stats dashboard, and gateway fallback fixes
AI gateway: - Add a generic, admin-selectable `client_profile` field on gateway_providers (e.g. "opencode") so a provider needing special request headers (OpenCode Zen's client-identity spoofing) is configured like any other provider, not hardcoded by name. - Track per-(provider, model) reliability/speed/latency health in memory, seeded from the existing gateway_usage_ledger at startup - purely observational, never influences routing. - New Stats tab on /admin/gateway: request volume, latency, per-model breakdowns, and reliability weight, charted with a vendored Chart.js and devplace's own theme tokens. - Record which model a failed request actually fell back to (fallback_used_route), surfaced in the Recent Failures table. - Stop excluding context_length errors from fallback, and skip a primary attempt outright when its known context window is already too small for the estimated request size, going straight to the fallback. - gateway_usage_ledger's provider/fallback_used_route columns and indexes are ensured centrally in database/schema.py's init_db(), the single point of truth for this table's schema. - Non-OpenAI upstream routing and client-model passthrough; trust only the upstream's own X-Gateway-Model header for served-model attribution. Devii agent: - Fix a real lockup: plan/verify tools could be individually disabled via the admin tool toggles while still being required by the protocol gate, permanently bricking any task that needed tools. They can no longer be disabled, and the gate now also checks the tool is actually offered. - Fix compaction being silently calibrated for a 1M-token model while running a much smaller one: context budget is now percentage-based and the summarizer's own request is sized to fit the real model. - Give a specific, actionable retry message when plan()'s own arguments get cut off by the output limit, and tighten its schema to discourage overlong plans. Other: - Backup service: offload completed backups to a remote Hetzner Storage Box. - Container manager: fix orphan blob leaks from sync races, add a two-phase plan/execute `system prune` CLI command. - Admin gateway UI: replace the JS-rendered model/provider tables with server-rendered forms and pages. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DhmEkvutuwtzFVcLbTrhdo
This commit is contained in:
@@ -4,125 +4,256 @@
|
||||
<link rel="stylesheet" href="{{ static_url('/static/css/gateway.css') }}">
|
||||
{% endblock %}
|
||||
{% block admin_content %}
|
||||
<div id="gateway-admin">
|
||||
<div class="admin-toolbar">
|
||||
<h2>Gateway routing</h2>
|
||||
<span class="admin-count" id="gw-count" role="status" aria-live="polite"></span>
|
||||
</div>
|
||||
<p class="gw-intro">Map any requested model name onto a provider and target model, each with its own pricing economy and an optional vision model for image to text merging. Image routes use a flat per-image price. Unmapped requests fall through to the default upstream unchanged.</p>
|
||||
|
||||
<section class="gw-section">
|
||||
<div class="gw-section-head">
|
||||
<h3>Providers</h3>
|
||||
</div>
|
||||
<p class="gw-section-hint">Named upstreams reused across model routes. A model route with a blank provider uses the default below.</p>
|
||||
<div class="gw-default" id="gw-default" role="status" aria-live="polite"></div>
|
||||
<div class="admin-table-wrap">
|
||||
<table class="admin-table">
|
||||
<caption class="sr-only">Providers</caption>
|
||||
<thead>
|
||||
<tr><th scope="col">Name</th><th scope="col">Base URL</th><th scope="col">Active</th><th scope="col" class="gw-actions">Actions</th></tr>
|
||||
</thead>
|
||||
<tbody id="gw-providers"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
<form class="gw-form" id="gw-provider-form" autocomplete="off" role="group" aria-label="Add or update provider">
|
||||
<p class="gw-form-title">Add or update provider</p>
|
||||
<div class="gw-field"><label for="gw-provider-name">Name</label><input type="text" id="gw-provider-name" name="name" placeholder="openrouter" required aria-required="true"></div>
|
||||
<div class="gw-field"><label for="gw-provider-base-url">Base URL (chat completions)</label><input type="url" id="gw-provider-base-url" name="base_url" placeholder="https://openrouter.ai/api/v1/chat/completions"></div>
|
||||
<div class="gw-field"><label for="gw-provider-api-key">API key</label><input type="password" id="gw-provider-api-key" name="api_key" placeholder="sk-..." autocomplete="new-password"></div>
|
||||
<div class="gw-field"><label for="gw-provider-active">Active</label><select id="gw-provider-active" name="is_active"><option value="1">Yes</option><option value="0">No</option></select></div>
|
||||
<div class="gw-form-actions"><button type="submit" class="admin-btn admin-btn-primary">Save provider</button></div>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section class="gw-section">
|
||||
<div class="gw-section-head">
|
||||
<h3>Model routes</h3>
|
||||
</div>
|
||||
<p class="gw-section-hint">Each source model maps to a provider and target model with its own economy. Chat uses cache-hit, cache-miss and output prices (USD per 1M tokens); embeddings use the input price; image routes use the input price as a flat USD per image; a vision model adds input and output pricing for the image description merge. An optional fallback model is retried once, automatically, whenever this route fails after its own retries are exhausted - pick any other already-configured model of the same kind.</p>
|
||||
<div class="admin-table-wrap">
|
||||
<table class="admin-table">
|
||||
<caption class="sr-only">Model routes</caption>
|
||||
<thead>
|
||||
<tr><th scope="col">Source</th><th scope="col">Provider</th><th scope="col">Target</th><th scope="col">Kind</th><th scope="col">Vision</th><th scope="col">Economy</th><th scope="col" class="gw-actions">Actions</th></tr>
|
||||
</thead>
|
||||
<tbody id="gw-models"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
<form class="gw-form" id="gw-model-form" autocomplete="off" role="group" aria-label="Add or update model route">
|
||||
<p class="gw-form-title">Add or update model route</p>
|
||||
<div class="gw-field"><label for="gw-model-source">Source model (requested)</label><input type="text" id="gw-model-source" name="source_model" placeholder="gpt-4o" required aria-required="true"></div>
|
||||
<div class="gw-field"><label for="gw-model-provider">Provider</label><select id="gw-model-provider" name="provider" data-provider-select></select></div>
|
||||
<div class="gw-field"><label for="gw-model-target">Target model (upstream)</label><input type="text" id="gw-model-target" name="target_model" placeholder="openai/gpt-4o" required aria-required="true"></div>
|
||||
<div class="gw-field"><label for="gw-model-kind">Kind</label><select id="gw-model-kind" name="kind"><option value="chat">chat</option><option value="embed">embed</option><option value="image">image</option></select></div>
|
||||
<div class="gw-field" data-kind-field="chat"><label for="gw-model-vision-provider">Vision provider</label><select id="gw-model-vision-provider" name="vision_provider" data-provider-select></select></div>
|
||||
<div class="gw-field" data-kind-field="chat"><label for="gw-model-vision-model">Vision model</label><input type="text" id="gw-model-vision-model" name="vision_model" placeholder="(optional) google/gemma-3-12b-it"></div>
|
||||
<div class="gw-field"><label for="gw-model-context">Context window</label><input type="number" id="gw-model-context" name="context_window" min="0" value="0"></div>
|
||||
<div class="gw-field"><label for="gw-model-active">Active</label><select id="gw-model-active" name="is_active"><option value="1">Yes</option><option value="0">No</option></select></div>
|
||||
<div class="gw-field"><label for="gw-model-fallback">Fallback model</label><select id="gw-model-fallback" name="fallback_model" title="Tried automatically when this model fails after retries. Only other models of the same kind are offered."><option value="">(none)</option></select></div>
|
||||
<div class="gw-field" data-kind-field="chat"><label for="gw-model-price-cache-hit">Price cache-hit / 1M ($)</label><input type="number" id="gw-model-price-cache-hit" name="price_cache_hit_per_m" min="0" step="0.0001" value="0"></div>
|
||||
<div class="gw-field" data-kind-field="chat"><label for="gw-model-price-cache-miss">Price cache-miss / 1M ($)</label><input type="number" id="gw-model-price-cache-miss" name="price_cache_miss_per_m" min="0" step="0.0001" value="0"></div>
|
||||
<div class="gw-field" data-kind-field="chat"><label for="gw-model-price-output">Price output / 1M ($)</label><input type="number" id="gw-model-price-output" name="price_output_per_m" min="0" step="0.0001" value="0"></div>
|
||||
<div class="gw-field" data-kind-field="embed chat"><label for="gw-model-price-input" id="gw-model-price-input-label">Price input / 1M ($) (embed/vision)</label><input type="number" id="gw-model-price-input" name="price_input_per_m" min="0" step="0.0001" value="0"></div>
|
||||
<p class="gw-form-title gw-form-subtitle" data-kind-field="chat embed">Tiered / off-peak pricing (optional)</p>
|
||||
<p class="gw-section-hint" data-kind-field="chat embed">Some providers charge a different rate once a request crosses a context-length threshold, or discount a fixed time-of-day window. Leave blank/zero to keep the flat rates above at all times.</p>
|
||||
<div class="gw-field" data-kind-field="chat embed"><label for="gw-model-tier-threshold">Tier-2 threshold (input tokens)</label><input type="number" id="gw-model-tier-threshold" name="context_tier_threshold_tokens" min="0" value="0" title="0 disables tiered pricing"></div>
|
||||
<div class="gw-field" data-kind-field="chat"><label for="gw-model-price-cache-hit-tier2">Tier-2 price cache-hit / 1M ($)</label><input type="number" id="gw-model-price-cache-hit-tier2" name="price_cache_hit_per_m_tier2" min="0" step="0.0001" placeholder="same as tier 1"></div>
|
||||
<div class="gw-field" data-kind-field="chat"><label for="gw-model-price-cache-miss-tier2">Tier-2 price cache-miss / 1M ($)</label><input type="number" id="gw-model-price-cache-miss-tier2" name="price_cache_miss_per_m_tier2" min="0" step="0.0001" placeholder="same as tier 1"></div>
|
||||
<div class="gw-field" data-kind-field="chat"><label for="gw-model-price-output-tier2">Tier-2 price output / 1M ($)</label><input type="number" id="gw-model-price-output-tier2" name="price_output_per_m_tier2" min="0" step="0.0001" placeholder="same as tier 1"></div>
|
||||
<div class="gw-field" data-kind-field="chat embed"><label for="gw-model-price-input-tier2">Tier-2 price input / 1M ($) (embed/vision)</label><input type="number" id="gw-model-price-input-tier2" name="price_input_per_m_tier2" min="0" step="0.0001" placeholder="same as tier 1"></div>
|
||||
<div class="gw-field" data-kind-field="chat embed image"><label for="gw-model-off-peak-start">Off-peak start (UTC)</label><input type="time" id="gw-model-off-peak-start" name="off_peak_start" title="Leave blank to disable off-peak discount"></div>
|
||||
<div class="gw-field" data-kind-field="chat embed image"><label for="gw-model-off-peak-end">Off-peak end (UTC)</label><input type="time" id="gw-model-off-peak-end" name="off_peak_end" title="Leave blank to disable off-peak discount"></div>
|
||||
<div class="gw-field" data-kind-field="chat embed image"><label for="gw-model-off-peak-discount">Off-peak discount (%)</label><input type="number" id="gw-model-off-peak-discount" name="off_peak_discount_pct" min="0" max="100" step="0.1" value="0"></div>
|
||||
<div class="gw-form-actions"><button type="submit" class="admin-btn admin-btn-primary">Save model route</button></div>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section class="gw-section">
|
||||
<div class="gw-section-head">
|
||||
<h3>Quota rules</h3>
|
||||
</div>
|
||||
<p class="gw-section-hint">Rolling 24h USD caps on <code class="gw-code">/openai/v1/*</code>. A rule scopes by any combination of role, specific user, and app label (the <code class="gw-code">X-App-Reference</code> header); the most specific active match wins, and a rule that omits a dimension pools spend across everyone matching it (e.g. an app-only rule caps that app's combined usage across all callers). With no matching rule, the global defaults below apply per caller. A limit of 0 means unlimited.</p>
|
||||
<div class="gw-default" id="gw-quota-defaults" role="status" aria-live="polite"></div>
|
||||
<div class="admin-table-wrap">
|
||||
<table class="admin-table">
|
||||
<caption class="sr-only">Quota rules</caption>
|
||||
<thead>
|
||||
<tr><th scope="col">Scope</th><th scope="col">Limit / 24h</th><th scope="col">Spent 24h</th><th scope="col">Active</th><th scope="col">Label</th><th scope="col" class="gw-actions">Actions</th></tr>
|
||||
</thead>
|
||||
<tbody id="gw-quota-rules"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
<form class="gw-form" id="gw-quota-form" autocomplete="off" role="group" aria-label="Add or update quota rule">
|
||||
<p class="gw-form-title">Add or update quota rule</p>
|
||||
<input type="hidden" id="gw-quota-uid" name="uid" value="">
|
||||
<div class="gw-field"><label for="gw-quota-owner-kind">Role</label>
|
||||
<select id="gw-quota-owner-kind" name="owner_kind">
|
||||
<option value="">any</option>
|
||||
<option value="user">member</option>
|
||||
<option value="admin">admin</option>
|
||||
<option value="anonymous">guest (unauthenticated)</option>
|
||||
<option value="internal">internal (DevPlace's own services)</option>
|
||||
<option value="key">static access key</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="gw-field"><label for="gw-quota-owner-id">Specific user uid</label><input type="text" id="gw-quota-owner-id" name="owner_id" placeholder="(optional) exact uid, blank = any"></div>
|
||||
<div class="gw-field"><label for="gw-quota-app-reference">App reference</label><input type="text" id="gw-quota-app-reference" name="app_reference" placeholder="(optional) devplace-bots-v-1-0-0, blank = any"></div>
|
||||
<div class="gw-field"><label for="gw-quota-limit">Limit / 24h ($)</label><input type="number" id="gw-quota-limit" name="limit_usd" min="0" step="0.01" value="0" title="0 = unlimited"></div>
|
||||
<div class="gw-field"><label for="gw-quota-active">Active</label><select id="gw-quota-active" name="is_active"><option value="1">Yes</option><option value="0">No</option></select></div>
|
||||
<div class="gw-field"><label for="gw-quota-label">Label</label><input type="text" id="gw-quota-label" name="label" placeholder="(optional) admin note" maxlength="200"></div>
|
||||
<div class="gw-form-actions">
|
||||
<button type="submit" class="admin-btn admin-btn-primary">Save quota rule</button>
|
||||
<button type="button" class="admin-btn admin-btn-sm" id="gw-quota-cancel-edit" hidden>Cancel edit</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
<div class="admin-toolbar">
|
||||
<h2>Gateway routing</h2>
|
||||
<span class="admin-count">{{ providers|length }} providers, {{ models|length }} routes, {{ quota_rules|length }} quota rules</span>
|
||||
</div>
|
||||
<p class="gw-intro">Map any requested model name onto a provider and target model, each with its own pricing economy and an optional vision model for image to text merging. Image routes use a flat per-image price. Unmapped requests fall through to the default upstream unchanged.</p>
|
||||
|
||||
<nav class="admin-tabs" aria-label="Gateway configuration">
|
||||
<a href="/admin/gateway?tab=models" class="admin-tab {% if tab == 'models' %}active{% endif %}">Models <span class="admin-tab-count">{{ models|length }}</span></a>
|
||||
<a href="/admin/gateway?tab=providers" class="admin-tab {% if tab == 'providers' %}active{% endif %}">Providers <span class="admin-tab-count">{{ providers|length }}</span></a>
|
||||
<a href="/admin/gateway?tab=quota" class="admin-tab {% if tab == 'quota' %}active{% endif %}">Quota rules <span class="admin-tab-count">{{ quota_rules|length }}</span></a>
|
||||
<a href="/admin/gateway?tab=stats" class="admin-tab {% if tab == 'stats' %}active{% endif %}">Stats</a>
|
||||
</nav>
|
||||
|
||||
{% if tab == 'models' %}
|
||||
<section class="gw-section">
|
||||
<div class="gw-section-head">
|
||||
<h3>Model routes</h3>
|
||||
<a href="/admin/gateway/models/new" class="admin-btn admin-btn-primary admin-btn-sm">Add model route</a>
|
||||
</div>
|
||||
<p class="gw-section-hint">Each source model maps to a provider and target model with its own economy. Chat uses cache-hit, cache-miss and output prices (USD per 1M tokens); embeddings use the input price; image routes use the input price as a flat USD per image; a vision model adds input and output pricing for the image description merge. An optional fallback model is retried once, automatically, whenever this route fails after its own retries are exhausted.</p>
|
||||
<div class="admin-table-wrap">
|
||||
<table class="admin-table">
|
||||
<caption class="sr-only">Model routes</caption>
|
||||
<thead>
|
||||
<tr><th scope="col">Source</th><th scope="col">Provider</th><th scope="col">Target</th><th scope="col">Kind</th><th scope="col">Vision</th><th scope="col">Economy</th><th scope="col" class="gw-actions">Actions</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% if not models %}
|
||||
<tr><td colspan="7" class="admin-empty">No model routes. Requests fall through to the default upstream.</td></tr>
|
||||
{% endif %}
|
||||
{% for m in models %}
|
||||
<tr>
|
||||
<td>{{ m.source_model }}</td>
|
||||
<td>{{ m.provider or "default" }}</td>
|
||||
<td><code class="gw-code">{{ m.target_model }}</code></td>
|
||||
<td>{{ m.kind }}</td>
|
||||
<td>
|
||||
{% if m.vision_model %}
|
||||
<code class="gw-code">{{ m.vision_provider or m.provider or "default" }}/{{ m.vision_model }}</code>
|
||||
{% else %}
|
||||
<span class="gw-muted">-</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if m.context_tier_threshold_tokens %}<span class="gw-badge" title="Tier-2 rates above {{ m.context_tier_threshold_tokens }} input tokens">tiered</span>{% endif %}
|
||||
{% if m.off_peak_start_minute is not none %}<span class="gw-badge" title="{{ m.off_peak_discount_pct }}% off during the configured UTC window">off-peak</span>{% endif %}
|
||||
{% if m.kind == 'image' and m.price_input_per_m %}<span class="gw-badge" title="Flat price per generated image">${{ m.price_input_per_m }}/img</span>{% endif %}
|
||||
{% if m.fallback_model %}<span class="gw-badge" title="Falls back to {{ m.fallback_model }} on failure">fallback: {{ m.fallback_model }}</span>{% endif %}
|
||||
{% if not m.context_tier_threshold_tokens and m.off_peak_start_minute is none and not (m.kind == 'image' and m.price_input_per_m) and not m.fallback_model %}<span class="gw-muted">-</span>{% endif %}
|
||||
</td>
|
||||
<td class="gw-actions">
|
||||
<a class="admin-btn admin-btn-sm" href="/admin/gateway/models/{{ m.source_model }}/edit">Edit</a>
|
||||
<form method="post" action="/admin/gateway/models/{{ m.source_model }}/delete" class="gw-inline-form">
|
||||
<button type="submit" class="admin-btn admin-btn-sm admin-btn-danger" data-confirm="Delete model route "{{ m.source_model }}"?">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
{% endif %}
|
||||
|
||||
{% if tab == 'providers' %}
|
||||
<section class="gw-section">
|
||||
<div class="gw-section-head">
|
||||
<h3>Providers</h3>
|
||||
<a href="/admin/gateway/providers/new" class="admin-btn admin-btn-primary admin-btn-sm">Add provider</a>
|
||||
</div>
|
||||
<p class="gw-section-hint">Named upstreams reused across model routes. A model route with a blank provider uses the default below.</p>
|
||||
<div class="gw-default">
|
||||
<strong>default</strong> (from <a href="/admin/services">Services config</a>):
|
||||
chat <code class="gw-code">{{ default_provider.model }}</code> at <code class="gw-code">{{ default_provider.base_url }}</code>,
|
||||
embed <code class="gw-code">{{ default_provider.embed_model }}</code>,
|
||||
image <code class="gw-code">{{ default_provider.image_model }}</code>,
|
||||
vision <code class="gw-code">{{ default_provider.vision_model }}</code>
|
||||
</div>
|
||||
<div class="admin-table-wrap">
|
||||
<table class="admin-table">
|
||||
<caption class="sr-only">Providers</caption>
|
||||
<thead>
|
||||
<tr><th scope="col">Name</th><th scope="col">Base URL</th><th scope="col">Active</th><th scope="col">Client profile</th><th scope="col" class="gw-actions">Actions</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% if not providers %}
|
||||
<tr><td colspan="5" class="admin-empty">No extra providers. Model routes with a blank provider use the default.</td></tr>
|
||||
{% endif %}
|
||||
{% for p in providers %}
|
||||
<tr>
|
||||
<td>{{ p.name }}</td>
|
||||
<td><code class="gw-code">{{ p.base_url }}</code></td>
|
||||
<td>{{ "yes" if p.is_active else "no" }}</td>
|
||||
<td>{{ p.client_profile or "generic" }}</td>
|
||||
<td class="gw-actions">
|
||||
<a class="admin-btn admin-btn-sm" href="/admin/gateway/providers/{{ p.name }}/edit">Edit</a>
|
||||
<form method="post" action="/admin/gateway/providers/{{ p.name }}/delete" class="gw-inline-form">
|
||||
<button type="submit" class="admin-btn admin-btn-sm admin-btn-danger" data-confirm="Delete provider "{{ p.name }}"?">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
{% endif %}
|
||||
|
||||
{% if tab == 'quota' %}
|
||||
<section class="gw-section">
|
||||
<div class="gw-section-head">
|
||||
<h3>Quota rules</h3>
|
||||
<a href="/admin/gateway/quota-rules/new" class="admin-btn admin-btn-primary admin-btn-sm">Add quota rule</a>
|
||||
</div>
|
||||
<p class="gw-section-hint">Rolling 24h USD caps on <code class="gw-code">/openai/v1/*</code>. A rule scopes by any combination of role, specific user, and app label (the <code class="gw-code">X-App-Reference</code> header); the most specific active match wins, and a rule that omits a dimension pools spend across everyone matching it. With no matching rule, the global defaults below apply per caller. A limit of 0 means unlimited.</p>
|
||||
<div class="gw-default">
|
||||
<strong>global defaults</strong> (from <a href="/admin/services">Services config</a>, apply per caller with no matching rule):
|
||||
member <code class="gw-code">{{ "$%.2f/24h"|format(quota_defaults.user) if quota_defaults.user else "unlimited" }}</code>,
|
||||
admin <code class="gw-code">{{ "$%.2f/24h"|format(quota_defaults.admin) if quota_defaults.admin else "unlimited" }}</code>,
|
||||
guest <code class="gw-code">{{ "$%.2f/24h"|format(quota_defaults.guest) if quota_defaults.guest else "unlimited" }}</code>,
|
||||
internal <code class="gw-code">{{ "$%.2f/24h"|format(quota_defaults.internal) if quota_defaults.internal else "unlimited" }}</code>,
|
||||
access key <code class="gw-code">{{ "$%.2f/24h"|format(quota_defaults.key) if quota_defaults.key else "unlimited" }}</code>
|
||||
</div>
|
||||
<div class="admin-table-wrap">
|
||||
<table class="admin-table">
|
||||
<caption class="sr-only">Quota rules</caption>
|
||||
<thead>
|
||||
<tr><th scope="col">Scope</th><th scope="col">Limit / 24h</th><th scope="col">Spent 24h</th><th scope="col">Active</th><th scope="col">Label</th><th scope="col" class="gw-actions">Actions</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% if not quota_rules %}
|
||||
<tr><td colspan="6" class="admin-empty">No quota rules. Every caller is capped by the global defaults above.</td></tr>
|
||||
{% endif %}
|
||||
{% for r in quota_rules %}
|
||||
<tr>
|
||||
<td><code class="gw-code">role={{ r.owner_kind or "any" }}, user={{ r.owner_id or "any" }}, app={{ r.app_reference or "any" }}</code></td>
|
||||
<td>{{ "$%.2f"|format(r.limit_usd) if r.limit_usd else "unlimited" }}</td>
|
||||
<td>${{ "%.4f"|format(r.spent_24h_usd) }}</td>
|
||||
<td>{{ "yes" if r.is_active else "no" }}</td>
|
||||
<td>{{ r.label }}</td>
|
||||
<td class="gw-actions">
|
||||
<a class="admin-btn admin-btn-sm" href="/admin/gateway/quota-rules/{{ r.uid }}/edit">Edit</a>
|
||||
<form method="post" action="/admin/gateway/quota-rules/{{ r.uid }}/reset" class="gw-inline-form">
|
||||
<button type="submit" class="admin-btn admin-btn-sm" data-confirm="Reset the counted 24h spend for this rule? The usage history is kept.">Reset spend</button>
|
||||
</form>
|
||||
<form method="post" action="/admin/gateway/quota-rules/{{ r.uid }}/delete" class="gw-inline-form">
|
||||
<button type="submit" class="admin-btn admin-btn-sm admin-btn-danger" data-confirm="Delete this quota rule?">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
{% endif %}
|
||||
|
||||
{% if tab == 'stats' %}
|
||||
<section class="gw-section" id="gw-stats-panel" data-stats-root>
|
||||
<div class="gw-stats-head">
|
||||
<p class="gw-section-hint" style="margin:0;">Request volume, latency, and per-model reliability, computed from the gateway usage ledger you already record - no separate data collection.</p>
|
||||
<select id="gw-stats-range">
|
||||
{% for r in stats_ranges %}
|
||||
<option value="{{ r }}" {% if r == '24h' %}selected{% endif %}>{{ r }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="gw-tiles">
|
||||
<div class="gw-tile"><div class="gw-tile-label">Total requests</div><div class="gw-tile-value" id="gw-stat-total-requests">-</div></div>
|
||||
<div class="gw-tile"><div class="gw-tile-label">Success rate</div><div class="gw-tile-value" id="gw-stat-success-rate">-</div></div>
|
||||
<div class="gw-tile"><div class="gw-tile-label">Models tracked</div><div class="gw-tile-value" id="gw-stat-models-tracked">-</div></div>
|
||||
<div class="gw-tile"><div class="gw-tile-label">Last updated</div><div class="gw-tile-value" id="gw-stat-generated-at">-</div></div>
|
||||
</div>
|
||||
|
||||
<div class="gw-charts-grid">
|
||||
<div class="gw-panel gw-wide"><h4>Requests over time</h4><div class="gw-chart-box"><canvas id="gw-chart-timeseries"></canvas></div></div>
|
||||
<div class="gw-panel"><h4>Success / failure</h4><div class="gw-chart-box"><canvas id="gw-chart-totals"></canvas></div></div>
|
||||
<div class="gw-panel"><h4>Requests by model</h4><div class="gw-chart-box"><canvas id="gw-chart-per-model"></canvas></div></div>
|
||||
<div class="gw-panel"><h4>Requests by endpoint</h4><div class="gw-chart-box"><canvas id="gw-chart-endpoints"></canvas></div></div>
|
||||
<div class="gw-panel"><h4>HTTP status codes</h4><div class="gw-chart-box"><canvas id="gw-chart-status-codes"></canvas></div></div>
|
||||
<div class="gw-panel"><h4>Streaming vs non-streaming</h4><div class="gw-chart-box"><canvas id="gw-chart-streaming"></canvas></div></div>
|
||||
<div class="gw-panel"><h4>Top failure reasons</h4><div class="gw-chart-box"><canvas id="gw-chart-failure-reasons"></canvas></div></div>
|
||||
<div class="gw-panel"><h4>Requests by hour of day (UTC)</h4><div class="gw-chart-box"><canvas id="gw-chart-hourly"></canvas></div></div>
|
||||
<div class="gw-panel"><h4>Latency distribution</h4><div class="gw-chart-box"><canvas id="gw-chart-latency-hist"></canvas></div></div>
|
||||
<div class="gw-panel"><h4>Tokens/sec distribution</h4><div class="gw-chart-box"><canvas id="gw-chart-tps-hist"></canvas></div></div>
|
||||
<div class="gw-panel"><h4>Model reliability weight</h4><div class="gw-chart-box"><canvas id="gw-chart-weight"></canvas></div></div>
|
||||
<div class="gw-panel"><h4>Prompt vs completion tokens</h4><div class="gw-chart-box"><canvas id="gw-chart-tokens"></canvas></div></div>
|
||||
</div>
|
||||
|
||||
<section class="gw-section">
|
||||
<div class="gw-section-head">
|
||||
<h3>Per-model detail</h3>
|
||||
<select id="gw-model-detail-select"><option value="">Select a model...</option></select>
|
||||
</div>
|
||||
<div id="gw-model-detail-empty-state" class="gw-section-hint">Pick a model above to see its own timeseries and latency distribution.</div>
|
||||
<div id="gw-model-detail-charts" hidden>
|
||||
<div class="gw-tiles">
|
||||
<div class="gw-tile"><div class="gw-tile-label">Requests</div><div class="gw-tile-value" id="gw-model-detail-requests">-</div></div>
|
||||
<div class="gw-tile"><div class="gw-tile-label">Success rate</div><div class="gw-tile-value" id="gw-model-detail-success-rate">-</div></div>
|
||||
<div class="gw-tile"><div class="gw-tile-label">Avg latency</div><div class="gw-tile-value" id="gw-model-detail-latency">-</div></div>
|
||||
<div class="gw-tile"><div class="gw-tile-label">Avg tokens/sec</div><div class="gw-tile-value" id="gw-model-detail-tps">-</div></div>
|
||||
</div>
|
||||
<div class="gw-charts-grid">
|
||||
<div class="gw-panel gw-wide"><h4>Requests over time</h4><div class="gw-chart-box"><canvas id="gw-chart-model-timeseries"></canvas></div></div>
|
||||
<div class="gw-panel"><h4>Latency distribution</h4><div class="gw-chart-box"><canvas id="gw-chart-model-latency-hist"></canvas></div></div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="gw-section">
|
||||
<h3>Model pool</h3>
|
||||
<div class="admin-table-wrap gw-table-scroll">
|
||||
<table class="admin-table">
|
||||
<caption class="sr-only">Model pool</caption>
|
||||
<thead>
|
||||
<tr><th scope="col">Model</th><th scope="col">Provider</th><th scope="col">Requests</th><th scope="col">Success</th><th scope="col">Avg latency</th><th scope="col">Avg tok/s</th><th scope="col">Weight</th><th scope="col">Circuit</th><th scope="col">Prompt tok</th><th scope="col">Completion tok</th></tr>
|
||||
</thead>
|
||||
<tbody id="gw-stats-model-table-body">
|
||||
<tr><td colspan="10" class="admin-empty">Loading...</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="gw-section">
|
||||
<h3>Recent failures</h3>
|
||||
<div class="admin-table-wrap gw-table-scroll">
|
||||
<table class="admin-table">
|
||||
<caption class="sr-only">Recent failures</caption>
|
||||
<thead>
|
||||
<tr><th scope="col">When</th><th scope="col">Model</th><th scope="col">Provider</th><th scope="col">Endpoint</th><th scope="col">Status</th><th scope="col">Reason</th><th scope="col">Fell back to</th></tr>
|
||||
</thead>
|
||||
<tbody id="gw-stats-failures-table-body">
|
||||
<tr><td colspan="7" class="admin-empty">Loading...</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% block extra_js %}
|
||||
{% if tab == 'stats' %}
|
||||
<script src="{{ static_url('/static/js/vendor/chart.js') }}"></script>
|
||||
<script type="module">
|
||||
import { GatewayAdmin } from "{{ static_url('/static/js/GatewayAdmin.js') }}";
|
||||
new GatewayAdmin(document.getElementById("gateway-admin")).start();
|
||||
import { GatewayStats } from "{{ static_url('/static/js/GatewayStats.js') }}";
|
||||
const gatewayStats = new GatewayStats(document.querySelector("[data-stats-root]"));
|
||||
gatewayStats.start();
|
||||
window.app.gatewayStats = gatewayStats;
|
||||
</script>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user