Fix admin authorization and harden chat requests
CI / check (22) (push) Successful in 10m3s
CI / check (24) (push) Successful in 9m34s

This commit is contained in:
2026-10-05 22:49:29 +02:00
parent e8cd13a0af
commit c48e1b17c4
38 changed files with 4897 additions and 1257 deletions
+12 -7
View File
@@ -4,6 +4,7 @@
import {stream} from "./api.js";
import {updateReasoning, finishReasoning} from "./reasoning.js";
import {appendSources} from "./webSearch.js";
import {createStreamRenderer} from "./streamRenderer.js";
// Keep the original nodes (including action handlers) until a committed answer arrives.
export async function regenerateInline({card, scroller, endpoint, payload, renderContent, complete}) {
@@ -25,8 +26,17 @@ export async function regenerateInline({card, scroller, endpoint, payload, rende
// Anchor to this response, including when a long old answer collapses.
update(() => card.replaceChildren(original[0].cloneNode(true), status, body));
card.setAttribute("aria-busy", "true");
const rendering = createStreamRenderer({
onThinking: text => update(() => updateReasoning(card, text, true)),
onReply: text => update(() => {
status.hidden = Boolean(text);
if (text) finishReasoning(card);
renderContent(body, text);
})
});
try {
await stream(endpoint, payload, {
...rendering,
onStatus: data => update(() => {
status.textContent = data.status === "searching" ? "Searching the web..."
: data.status === "analyzing" ? "Analyzing attachments..." : "Generating...";
@@ -35,20 +45,15 @@ export async function regenerateInline({card, scroller, endpoint, payload, rende
appendSources(card, data.sources);
}
}),
onThinking: ({fullThinking}) => update(() => updateReasoning(card, fullThinking, true)),
onChunk: ({fullReply}) => update(() => {
status.hidden = Boolean(fullReply);
if (fullReply) finishReasoning(card);
renderContent(body, fullReply);
}),
onError: ({error}) => { throw new Error(error || "Unable to regenerate message."); },
onDone: ({message}) => {
if (!message) throw new Error("Missing regenerated response.");
rendering.dispose();
update(() => complete(message));
committed = true;
}
});
} finally {
rendering.dispose();
// Bei Fehler oder Abbruch die ursprünglichen Knoten samt Ereignishandlern wieder einsetzen.
if (!committed) update(() => card.replaceChildren(...original));
card.removeAttribute("aria-busy");