Files
bookapp/templates/system_status.html
Mike Wichers 83a6a4315b Blueprint v2.4-2.6: Style Rules UI, Lore RAG, Thread Tracking, Redo Book
v2.4 — Item 7: Refresh Style Guidelines
- web/routes/admin.py: Added /admin/refresh-style-guidelines route (AJAX-aware)
- templates/system_status.html: Added 'Refresh Style Rules' button with spinner

v2.5 — Item 8: Lore & Location RAG-Lite
- story/bible_tracker.py: Added update_lore_index() — extracts location/item
  descriptions from chapters into tracking_lore.json
- story/writer.py: Reads chapter locations/key_items, builds LORE_CONTEXT block
  injected into the prompt (graceful degradation if no tags)
- cli/engine.py: Loads tracking_lore.json on resume, calls update_lore_index
  after each chapter, saves tracking_lore.json

v2.5 — Item 9: Structured Story State (Thread Tracking)
- story/state.py (new): load_story_state, update_story_state (extracts
  active_threads, immediate_handoff, resolved_threads via model_logic),
  format_for_prompt (structured context replacing the prev_sum blob)
- cli/engine.py: Loads story_state.json on resume, uses format_for_prompt as
  summary_ctx for write_chapter, updates state after each chapter accepted

v2.6 — Item 10: Redo Book
- templates/consistency_report.html: Added 'Redo Book' form with instruction
  input and confirmation dialog
- web/routes/run.py: Added revise_book route — creates new Run, queues
  generate_book_task with user instruction as feedback

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-21 01:35:43 -05:00

270 lines
11 KiB
HTML

{% extends "base.html" %}
{% block content %}
<div class="row mb-4">
<div class="col-md-8">
<h2><i class="fas fa-server me-2"></i>System Status</h2>
<p class="text-muted">AI Model Health, Selection Reasoning, and Availability.</p>
</div>
<div class="col-md-4 text-end">
<a href="{{ url_for('project.index') }}" class="btn btn-outline-secondary me-2">Back to Dashboard</a>
<button id="styleBtn" class="btn btn-outline-info me-2" onclick="refreshStyleGuidelines()">
<span id="styleIcon"><i class="fas fa-filter me-2"></i></span>
<span id="styleSpinner" class="spinner-border spinner-border-sm me-2 d-none" role="status"></span>
<span id="styleLabel">Refresh Style Rules</span>
</button>
<button id="refreshBtn" class="btn btn-primary" onclick="refreshModels()">
<span id="refreshIcon"><i class="fas fa-sync me-2"></i></span>
<span id="refreshSpinner" class="spinner-border spinner-border-sm me-2 d-none" role="status"></span>
<span id="refreshLabel">Refresh & Optimize</span>
</button>
</div>
</div>
{% if cache.error %}
<div class="alert alert-danger shadow-sm">
<h5 class="alert-heading"><i class="fas fa-exclamation-triangle me-2"></i>Last Scan Error</h5>
<p class="mb-0">{{ cache.error }}</p>
</div>
{% endif %}
<div class="card shadow-sm mb-4">
<div class="card-header bg-light">
<h5 class="mb-0"><i class="fas fa-robot me-2"></i>AI Model Selection</h5>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-hover align-middle mb-0">
<thead class="table-light">
<tr>
<th style="width: 15%">Role</th>
<th style="width: 25%">Selected Model</th>
<th style="width: 15%">Est. Cost</th>
<th>Selection Reasoning</th>
</tr>
</thead>
<tbody>
{% if models %}
{% for role, info in models.items() %}
{% if role != 'ranking' %}
<tr>
<td class="fw-bold text-uppercase">{{ role }}</td>
<td>
<span class="badge bg-info text-dark">{{ info.model }}</span>
</td>
<td>
<span class="badge bg-light text-dark border">{{ info.estimated_cost }}</span>
</td>
<td class="small text-muted">
{{ info.reason }}
</td>
</tr>
{% endif %}
{% endfor %}
<tr>
<td class="fw-bold text-uppercase">Image</td>
<td>
{% if image_model %}
<span class="badge bg-success">{{ image_model }}</span>
{% else %}
<span class="badge bg-danger">Unavailable</span>
{% endif %}
</td>
<td>
<span class="badge bg-light text-dark border">{{ image_source or 'None' }}</span>
</td>
<td class="small text-muted">
{% if image_model %}Imagen model used for book cover generation.{% else %}No image generation model could be initialized. Check GCP credentials or Gemini API key.{% endif %}
</td>
</tr>
{% else %}
<tr>
<td colspan="3" class="text-center py-4 text-muted">
<i class="fas fa-exclamation-circle me-2"></i>No model configuration found.
<br>Click <strong>Refresh & Optimize</strong> to scan available Gemini models.
</td>
</tr>
{% endif %}
</tbody>
</table>
</div>
</div>
</div>
<!-- Ranked Models -->
<div class="card shadow-sm mb-4">
<div class="card-header bg-light">
<h5 class="mb-0"><i class="fas fa-list-ol me-2"></i>All Models Ranked</h5>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-hover align-middle mb-0">
<thead class="table-light">
<tr>
<th style="width: 10%">Rank</th>
<th style="width: 30%">Model Name</th>
<th style="width: 15%">Est. Cost</th>
<th>Reasoning</th>
</tr>
</thead>
<tbody>
{% if models and models.ranking %}
{% for item in models.ranking %}
<tr>
<td class="fw-bold">{{ loop.index }}</td>
<td><span class="badge bg-secondary">{{ item.model }}</span></td>
<td><small>{{ item.estimated_cost }}</small></td>
<td class="small text-muted">{{ item.reason }}</td>
</tr>
{% endfor %}
{% else %}
<tr>
<td colspan="3" class="text-center py-4 text-muted">
No ranking data available. Refresh models to generate.
</td>
</tr>
{% endif %}
</tbody>
</table>
</div>
</div>
</div>
<!-- Raw API Output -->
<div class="card shadow-sm mb-4">
<div class="card-header bg-light d-flex justify-content-between align-items-center" style="cursor: pointer;" data-bs-toggle="collapse" data-bs-target="#rawOutput">
<h5 class="mb-0"><i class="fas fa-terminal me-2"></i>Raw API Output</h5>
<span class="badge bg-secondary">Click to Toggle</span>
</div>
<div id="rawOutput" class="collapse">
<div class="card-body bg-dark text-light font-monospace">
<p class="text-muted mb-2"># Full list of models returned by google.generativeai.list_models():</p>
<ul class="list-unstyled mb-0" style="column-count: 2;">
{% if cache.raw_models %}
{% for m in cache.raw_models %}
<li>
<span class="{{ 'text-success' if 'gemini' in m else 'text-muted' }}">{{ m }}</span>
</li>
{% endfor %}
{% else %}
<li class="text-muted">No raw data available. Run "Refresh & Optimize".</li>
{% endif %}
</ul>
</div>
</div>
</div>
<!-- Cache Info -->
<div class="card shadow-sm">
<div class="card-header bg-light">
<h5 class="mb-0"><i class="fas fa-clock me-2"></i>Cache Status</h5>
</div>
<div class="card-body">
<p class="mb-1">
<strong>Last Scan:</strong>
{% if cache and cache.timestamp %}
{{ datetime.fromtimestamp(cache.timestamp).strftime('%Y-%m-%d %H:%M:%S') }} UTC
{% else %}
Never
{% endif %}
</p>
<p class="mb-0">
<strong>Next Refresh:</strong>
{% if cache and cache.timestamp %}
{% set expires = cache.timestamp + 86400 %}
{% set now_ts = datetime.utcnow().timestamp() %}
{% if expires > now_ts %}
{% set remaining = (expires - now_ts) | int %}
{% set h = remaining // 3600 %}{% set m = (remaining % 3600) // 60 %}
in {{ h }}h {{ m }}m
<span class="badge bg-success ms-1">Cache Valid</span>
{% else %}
<span class="badge bg-warning text-dark">Expired — click Refresh &amp; Optimize</span>
{% endif %}
{% else %}
<span class="badge bg-warning text-dark">No cache — click Refresh &amp; Optimize</span>
{% endif %}
</p>
<p class="text-muted small mt-2 mb-0">Model selection is cached for 24 hours to save API calls.</p>
</div>
</div>
<!-- Toast notification -->
<div class="position-fixed bottom-0 end-0 p-3" style="z-index: 1100">
<div id="refreshToast" class="toast align-items-center border-0" role="alert" aria-live="assertive" aria-atomic="true">
<div class="d-flex">
<div id="toastBody" class="toast-body fw-semibold"></div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast"></button>
</div>
</div>
</div>
<script>
async function refreshModels() {
const btn = document.getElementById('refreshBtn');
const icon = document.getElementById('refreshIcon');
const spinner = document.getElementById('refreshSpinner');
const label = document.getElementById('refreshLabel');
btn.disabled = true;
icon.classList.add('d-none');
spinner.classList.remove('d-none');
label.textContent = 'Processing...';
try {
const resp = await fetch("{{ url_for('admin.optimize_models') }}", {
method: 'POST',
headers: { 'X-Requested-With': 'XMLHttpRequest' }
});
const data = await resp.json();
showToast(data.message, resp.ok ? 'bg-success text-white' : 'bg-danger text-white');
if (resp.ok) {
setTimeout(() => location.reload(), 1500);
}
} catch (err) {
showToast('Request failed: ' + err.message, 'bg-danger text-white');
} finally {
btn.disabled = false;
icon.classList.remove('d-none');
spinner.classList.add('d-none');
label.textContent = 'Refresh & Optimize';
}
}
async function refreshStyleGuidelines() {
const btn = document.getElementById('styleBtn');
const icon = document.getElementById('styleIcon');
const spinner = document.getElementById('styleSpinner');
const label = document.getElementById('styleLabel');
btn.disabled = true;
icon.classList.add('d-none');
spinner.classList.remove('d-none');
label.textContent = 'Updating...';
try {
const resp = await fetch("{{ url_for('admin.refresh_style_guidelines_route') }}", {
method: 'POST',
headers: { 'X-Requested-With': 'XMLHttpRequest' }
});
const data = await resp.json();
showToast(data.message, resp.ok ? 'bg-success text-white' : 'bg-danger text-white');
} catch (err) {
showToast('Request failed: ' + err.message, 'bg-danger text-white');
} finally {
btn.disabled = false;
icon.classList.remove('d-none');
spinner.classList.add('d-none');
label.textContent = 'Refresh Style Rules';
}
}
function showToast(message, classes) {
const toast = document.getElementById('refreshToast');
const body = document.getElementById('toastBody');
toast.className = 'toast align-items-center border-0 ' + classes;
body.textContent = message;
bootstrap.Toast.getOrCreateInstance(toast, { delay: 4000 }).show();
}
</script>
{% endblock %}