Fix admin authorization and harden chat requests
This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user