Stabilize search pipeline and improve preview diagnostics
build-push / docker (push) Successful in 4m14s
build-push / docker (push) Successful in 4m14s
This commit is contained in:
+39
-5
@@ -68,12 +68,36 @@ function logEvent(type, payload) {
|
||||
|
||||
function safeStringify(value) {
|
||||
try {
|
||||
return JSON.stringify(value, null, 2);
|
||||
return JSON.stringify(compactPayload(value), null, 2);
|
||||
} catch {
|
||||
return String(value);
|
||||
}
|
||||
}
|
||||
|
||||
function compactPayload(value, depth = 0) {
|
||||
if (depth > 3) {
|
||||
return "[truncated]";
|
||||
}
|
||||
if (Array.isArray(value)) {
|
||||
if (value.length > 8) {
|
||||
return {
|
||||
type: "array",
|
||||
length: value.length,
|
||||
sample: value.slice(0, 5).map((item) => compactPayload(item, depth + 1)),
|
||||
};
|
||||
}
|
||||
return value.map((item) => compactPayload(item, depth + 1));
|
||||
}
|
||||
if (value && typeof value === "object") {
|
||||
const entries = Object.entries(value);
|
||||
return Object.fromEntries(entries.map(([key, item]) => [key, compactPayload(item, depth + 1)]));
|
||||
}
|
||||
if (typeof value === "string" && value.length > 500) {
|
||||
return `${value.slice(0, 500)}...`;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function renderLogs() {
|
||||
debugSummary.textContent = `${debugEntries.length} events captured`;
|
||||
debugLogList.innerHTML = "";
|
||||
@@ -194,15 +218,24 @@ async function api(path, options = {}) {
|
||||
bodyPreview: typeof options.body === "string" ? options.body.slice(0, 800) : "[non-string body]",
|
||||
});
|
||||
const response = await fetch(path, options);
|
||||
const data = await response.json().catch(() => ({}));
|
||||
const rawText = await response.text();
|
||||
let data = {};
|
||||
if (rawText) {
|
||||
try {
|
||||
data = JSON.parse(rawText);
|
||||
} catch {
|
||||
data = { rawText };
|
||||
}
|
||||
}
|
||||
logEvent("api:response", {
|
||||
path,
|
||||
status: response.status,
|
||||
ok: response.ok,
|
||||
body: data,
|
||||
body: compactPayload(data),
|
||||
});
|
||||
if (!response.ok) {
|
||||
const error = new Error(data.error || "request failed");
|
||||
const message = data.error || data.rawText || `request failed (${response.status})`;
|
||||
const error = new Error(message);
|
||||
error.status = response.status;
|
||||
error.data = data;
|
||||
throw error;
|
||||
@@ -263,7 +296,8 @@ function renderResults(results) {
|
||||
image.src = item.thumbnailUrl || "https://placehold.co/1280x720/0a0a0a/ffffff?text=Preview";
|
||||
image.alt = item.title;
|
||||
node.querySelector("h3").textContent = item.title;
|
||||
node.querySelector("p").textContent = item.reason;
|
||||
node.querySelector(".result-snippet").textContent = item.snippet || item.reason || item.source || "";
|
||||
node.querySelector(".result-reason").textContent = item.reason ? `AI note: ${item.reason}` : "";
|
||||
node.querySelector(".source-badge").textContent = item.source;
|
||||
if (item.previewVideoUrl) {
|
||||
attachVideoSource(previewVideo, item.previewVideoUrl);
|
||||
|
||||
Reference in New Issue
Block a user