feat: add seo_meta service for AI-generated SEO metadata with CLI management and database layer

Implement a new `SeoMetaService` subservice that generates clean SEO title/description/keywords for published content items, distinct from the existing SEO diagnostics auditor. Add `seo_metadata` polymorphic table with soft-delete support, batch query methods, and usage tracking. Extend the CLI with `seo-meta prune` and `seo-meta clear` commands for job row lifecycle management. Wire `schedule_seo_meta_for_table` into content creation and editing flows in `content.py`. Document the new service in `AGENTS.md` and `README.md`, including the `extra_head` site setting for custom `<head>` injection.
This commit is contained in:
2026-06-19 20:15:22 +00:00
parent 426d3639c6
commit d10f1af118
51 changed files with 2262 additions and 93 deletions
+184
View File
@@ -159,6 +159,154 @@
transition: width 0.3s ease;
}
.ds-progress-bar.is-indeterminate {
width: 40% !important;
animation: ds-indeterminate 1.2s ease-in-out infinite;
}
@keyframes ds-indeterminate {
0% { margin-left: -40%; }
100% { margin-left: 100%; }
}
.ds-phase-timeline {
list-style: none;
margin: 0 0 var(--space-md);
padding: 0;
display: flex;
gap: var(--space-sm);
counter-reset: ds-phase;
}
.ds-phase {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
gap: 4px;
position: relative;
text-align: center;
font-size: 0.6875rem;
color: var(--text-muted);
}
.ds-phase::after {
content: "";
position: absolute;
top: 13px;
left: 50%;
width: 100%;
height: 2px;
background: var(--border);
z-index: 0;
}
.ds-phase:last-child::after {
display: none;
}
.ds-phase-dot {
width: 26px;
height: 26px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
background: var(--bg-card);
border: 2px solid var(--border);
color: var(--text-muted);
font-size: 0.75rem;
font-weight: 600;
position: relative;
z-index: 1;
transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}
.ds-phase.is-active .ds-phase-dot {
border-color: var(--accent);
color: var(--accent);
animation: ds-pulse 1.4s ease-in-out infinite;
}
.ds-phase.is-active .ds-phase-name {
color: var(--text-primary);
font-weight: 600;
}
.ds-phase.is-done .ds-phase-dot {
background: var(--accent);
border-color: var(--accent);
color: var(--white);
}
.ds-phase.is-done .ds-phase-name {
color: var(--text-secondary);
}
@keyframes ds-pulse {
0%, 100% { box-shadow: 0 0 0 0 rgba(var(--accent-rgb), 0.4); }
50% { box-shadow: 0 0 0 6px rgba(var(--accent-rgb), 0); }
}
.ds-details {
display: flex;
flex-wrap: wrap;
gap: var(--space-sm);
margin-top: var(--space-md);
}
.ds-detail-card {
flex: 1 1 200px;
min-width: 0;
background: var(--bg-card-hover);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: var(--space-sm) var(--space-md);
font-size: 0.8125rem;
}
.ds-detail-card.is-running {
background: linear-gradient(90deg, var(--bg-card-hover) 25%, var(--bg-card) 50%, var(--bg-card-hover) 75%);
background-size: 400% 100%;
animation: ds-shimmer 1.4s ease infinite;
}
@keyframes ds-shimmer {
0% { background-position: 100% 0; }
100% { background-position: -100% 0; }
}
.ds-detail-title {
font-weight: 600;
color: var(--text-primary);
display: flex;
align-items: center;
gap: var(--space-sm);
}
.ds-detail-body {
color: var(--text-secondary);
margin-top: 2px;
}
.ds-backend-badge {
font-size: 0.6875rem;
padding: 1px 8px;
border-radius: 999px;
border: 1px solid var(--border);
text-transform: uppercase;
letter-spacing: 0.03em;
}
.ds-backend-gateway {
color: var(--accent);
border-color: var(--accent);
}
.ds-backend-local {
color: var(--text-muted);
}
.ds-timeline {
list-style: none;
margin: var(--space-md) 0 0;
@@ -172,6 +320,28 @@
.ds-timeline li {
padding: 4px 0;
border-bottom: 1px solid var(--border);
display: flex;
gap: var(--space-sm);
}
.ds-log-time {
color: var(--text-muted);
font-variant-numeric: tabular-nums;
flex-shrink: 0;
font-size: 0.75rem;
}
.ds-log-text {
min-width: 0;
overflow-wrap: anywhere;
}
@media (prefers-reduced-motion: reduce) {
.ds-progress-bar.is-indeterminate,
.ds-phase.is-active .ds-phase-dot,
.ds-detail-card.is-running {
animation: none;
}
}
.ds-done {
@@ -415,3 +585,17 @@ dp-deepsearch-chat {
max-height: 70vh;
}
}
@media (max-width: 560px) {
.ds-phase-name {
display: none;
}
.ds-phase-timeline {
gap: 4px;
}
.ds-detail-card {
flex-basis: 100%;
}
}
+1
View File
@@ -9,6 +9,7 @@
--bg-modal: #1a1030;
--accent: #ff6b35;
--accent-rgb: 255, 107, 53;
--accent-hover: #ff7d4d;
--accent-light: rgba(255, 107, 53, 0.12);
--accent-2: #ff4f8b;
+166 -10
View File
@@ -3,6 +3,21 @@
import { Http } from "./Http.js";
import { DeepsearchProgressSocket } from "./DeepsearchProgressSocket.js";
const PHASE_ORDER = [
"planning",
"searching",
"crawling",
"indexing",
"analysis",
"synthesis",
];
const AGENT_LABELS = {
summarizer: "Summarizer",
critic: "Critic",
linker: "Linker",
};
export class DeepsearchTool {
constructor() {
this.root = document.querySelector("[data-deepsearch-tool]");
@@ -13,6 +28,8 @@ export class DeepsearchTool {
this.statusText = this.root.querySelector("[data-deepsearch-status]");
this.countText = this.root.querySelector("[data-deepsearch-count]");
this.bar = this.root.querySelector("[data-deepsearch-bar]");
this.timeline = this.root.querySelector("[data-deepsearch-timeline]");
this.details = this.root.querySelector("[data-deepsearch-details]");
this.log = this.root.querySelector("[data-deepsearch-log]");
this.done = this.root.querySelector("[data-deepsearch-done]");
this.openLink = this.root.querySelector("[data-deepsearch-open]");
@@ -20,8 +37,15 @@ export class DeepsearchTool {
this.resumeBtn = this.root.querySelector("[data-deepsearch-resume]");
this.cancelBtn = this.root.querySelector("[data-deepsearch-cancel]");
this.runBtn = this.form.querySelector("[data-deepsearch-run]");
this.phaseNodes = {};
if (this.timeline) {
this.timeline.querySelectorAll("[data-deepsearch-phase]").forEach((node) => {
this.phaseNodes[node.getAttribute("data-deepsearch-phase")] = node;
});
}
this.socket = null;
this.uid = null;
this.currentPhase = null;
this._bind();
}
@@ -61,13 +85,21 @@ export class DeepsearchTool {
this.done.hidden = true;
this.live.hidden = false;
this.log.innerHTML = "";
if (this.details) this.details.innerHTML = "";
this.bar.style.width = "0%";
this.bar.classList.remove("is-indeterminate");
this.countText.textContent = "";
this.statusText.textContent = "Starting…";
this.runBtn.disabled = true;
this.pauseBtn.hidden = false;
this.resumeBtn.hidden = true;
this.cancelBtn.hidden = false;
this.currentPhase = null;
Object.values(this.phaseNodes).forEach((node) => {
node.classList.remove("is-active", "is-done");
node.classList.add("is-pending");
node.removeAttribute("aria-current");
});
}
async _control(action) {
@@ -101,35 +133,89 @@ export class DeepsearchTool {
this.socket.connect();
}
_setPhase(phase) {
if (!(phase in this.phaseNodes)) return;
this.currentPhase = phase;
const target = PHASE_ORDER.indexOf(phase);
PHASE_ORDER.forEach((name, index) => {
const node = this.phaseNodes[name];
if (!node) return;
node.classList.remove("is-active", "is-done", "is-pending");
node.removeAttribute("aria-current");
if (index < target) {
node.classList.add("is-done");
} else if (index === target) {
node.classList.add("is-active");
node.setAttribute("aria-current", "step");
} else {
node.classList.add("is-pending");
}
});
this.bar.classList.add("is-indeterminate");
}
_frame(frame) {
const type = frame.type;
if (type === "stage") {
if (type === "phase") {
this._setPhase(frame.phase);
if (frame.label) this.statusText.textContent = frame.label;
} else if (type === "stage") {
this.statusText.textContent = frame.message || "Working…";
this._appendLog(frame.message || frame.stage);
} else if (type === "substep") {
this._appendLog(frame.message);
} else if (type === "queries") {
this._appendLog(`Planned ${frame.queries.length} queries`);
} else if (type === "candidates") {
this._appendLog(`Found ${frame.count} candidate sources`);
} else if (type === "rsearch") {
this._appendLog(
`Web search ${frame.endpoint || ""} ${frame.success ? "ok" : "failed"}`,
);
} else if (type === "progress") {
const total = frame.total || 1;
const done = frame.done || 0;
this.bar.style.width = `${Math.round((done / total) * 100)}%`;
this.countText.textContent = `${done} / ${total} sources`;
this._setBar(frame.done, frame.total);
this.countText.textContent = `${frame.done || 0} / ${frame.total || 0} sources`;
if (frame.message) this.statusText.textContent = frame.message;
} else if (type === "page_loaded") {
this.bar.style.width = `${Math.round((frame.done / frame.total) * 100)}%`;
this.bar.classList.remove("is-indeterminate");
this._setBar(frame.done, frame.total);
this.countText.textContent = `${frame.done} / ${frame.total} sources`;
this._appendLog(`${frame.source} ${frame.title || frame.url}`);
const tag = frame.render ? "rendered" : frame.source;
const ms = frame.elapsed_ms ? ` (${frame.elapsed_ms}ms)` : "";
this._appendLog(`${tag} ${frame.title || frame.url}${ms}`);
} else if (type === "page_cached") {
this._appendLog(`Cached ${frame.url}`);
} else if (type === "page_skipped") {
this._appendLog(`Skipped ${frame.url} - ${frame.reason || "no content"}`);
} else if (type === "page_duplicate") {
this._appendLog(`Duplicate ${frame.url}`);
} else if (type === "embed_batch") {
this.bar.classList.remove("is-indeterminate");
this._setBar(frame.done, frame.total);
this.statusText.textContent = frame.message || "Embedding";
this._embedCard(frame);
} else if (type === "embed_done") {
this._embedDone(frame);
this._appendLog(`Indexed ${frame.chunk_count} chunks (${frame.backend})`);
} else if (type === "agent") {
this.statusText.textContent = frame.message || "Analysing";
this._appendLog(`Agent: ${frame.agent}`);
this._agentCard(frame);
} else if (type === "report_ready") {
this.bar.classList.remove("is-indeterminate");
this.statusText.textContent = "Compiling report…";
} else if (type === "done") {
this.bar.classList.remove("is-indeterminate");
this.bar.style.width = "100%";
PHASE_ORDER.forEach((name) => {
const node = this.phaseNodes[name];
if (node) {
node.classList.remove("is-active", "is-pending");
node.classList.add("is-done");
}
});
this.statusText.textContent = "Done";
this._finish(frame.session_url || `/tools/deepsearch/${this.uid}/session`);
} else if (type === "failed") {
this.bar.classList.remove("is-indeterminate");
this.statusText.textContent = "Failed";
this._setError(frame.message || frame.error || "The research failed.");
this.runBtn.disabled = false;
@@ -138,6 +224,68 @@ export class DeepsearchTool {
}
}
_setBar(done, total) {
const safeTotal = total || 1;
const pct = Math.min(100, Math.round(((done || 0) / safeTotal) * 100));
this.bar.style.width = `${pct}%`;
}
_embedCard(frame) {
if (!this.details) return;
let card = this.details.querySelector("[data-ds-card='embed']");
if (!card) {
card = document.createElement("div");
card.className = "ds-detail-card";
card.setAttribute("data-ds-card", "embed");
this.details.appendChild(card);
}
const badge = `<span class="ds-backend-badge ds-backend-${frame.backend}">${frame.backend}</span>`;
card.innerHTML =
`<div class="ds-detail-title">Embedding ${badge}</div>` +
`<div class="ds-detail-body">Batch ${frame.batch} / ${frame.total_batches} - ${frame.done} / ${frame.total} chunks</div>`;
}
_embedDone(frame) {
if (!this.details) return;
let card = this.details.querySelector("[data-ds-card='embed']");
if (!card) {
card = document.createElement("div");
card.className = "ds-detail-card";
card.setAttribute("data-ds-card", "embed");
this.details.appendChild(card);
}
const badge = `<span class="ds-backend-badge ds-backend-${frame.backend}">${frame.backend}</span>`;
card.innerHTML =
`<div class="ds-detail-title">Indexing complete ${badge}</div>` +
`<div class="ds-detail-body">${frame.chunk_count} chunks embedded</div>`;
}
_agentCard(frame) {
if (!this.details) return;
const label = AGENT_LABELS[frame.agent] || frame.agent;
let card = this.details.querySelector(`[data-ds-card='agent-${frame.agent}']`);
if (!card) {
card = document.createElement("div");
card.className = "ds-detail-card";
card.setAttribute("data-ds-card", `agent-${frame.agent}`);
this.details.appendChild(card);
}
if (frame.status === "done") {
card.classList.remove("is-running");
const tokens = `${frame.tokens_in || 0} in / ${frame.tokens_out || 0} out tok`;
card.innerHTML =
`<div class="ds-detail-title">${label} done</div>` +
`<div class="ds-detail-body">${frame.elapsed_ms || 0}ms - ${tokens}</div>`;
} else {
card.classList.add("is-running");
card.innerHTML =
`<div class="ds-detail-title">${label}</div>` +
`<div class="ds-detail-body">${frame.message || "Working"}</div>`;
this.statusText.textContent = frame.message || label;
this._appendLog(`Agent: ${label}`);
}
}
_finish(sessionUrl) {
this.runBtn.disabled = false;
this.pauseBtn.hidden = true;
@@ -145,12 +293,20 @@ export class DeepsearchTool {
this.cancelBtn.hidden = true;
this.done.hidden = false;
this.openLink.href = sessionUrl;
window.location.assign(sessionUrl);
}
_appendLog(text) {
if (!text) return;
const item = document.createElement("li");
item.textContent = text;
const stamp = document.createElement("span");
stamp.className = "ds-log-time";
stamp.textContent = new Date().toLocaleTimeString();
const body = document.createElement("span");
body.className = "ds-log-text";
body.textContent = text;
item.appendChild(stamp);
item.appendChild(body);
this.log.prepend(item);
}
+8 -2
View File
@@ -26,10 +26,16 @@ export class Http {
return { data, message };
}
static _error(message, status) {
const error = new Error(message);
error.status = status;
return error;
}
static async getJson(url) {
const response = await fetch(url, { headers: { "Accept": "application/json" } });
if (!response.ok) {
throw new Error(`request failed with status ${response.status}`);
throw Http._error(`request failed with status ${response.status}`, response.status);
}
return response.json();
}
@@ -91,7 +97,7 @@ export class Http {
if (!response.ok) {
const { message } = await Http._messageFrom(response);
if (!options.silent) Http.notifyError(message);
throw new Error(message);
throw Http._error(message, response.status);
}
return response.json();
}
+3
View File
@@ -60,6 +60,9 @@ export class PushManager {
this.refreshTriggerVisibility();
} catch (error) {
if (error.status === 401) {
return;
}
console.error("Error registering push notifications:", error);
if (!silent) {
window.app.dialog.alert({