add JSDoc comments because yes

This commit is contained in:
2026-09-25 17:14:56 +02:00
parent 9020356e62
commit 0a24035b27
62 changed files with 197 additions and 0 deletions
+5
View File
@@ -1,3 +1,6 @@
/**
* @file Bündelt JSON-Anfragen und verarbeitet Ereignisse gestreamter Chat-Antworten im Browser.
*/
export async function request(url, data, method = "POST") {
try {
const res = await fetch(url, {
@@ -60,6 +63,7 @@ export async function stream(url, data, handlers = {}, signal = undefined) {
if (done) break;
buffer += decoder.decode(value, {stream: true});
const parts = buffer.split(/\r?\n\r?\n/);
// Das letzte SSE-Ereignis kann unvollständig sein und wird mit dem nächsten Netzwerkblock ergänzt.
buffer = parts.pop() || "";
for (const part of parts) {
const lines = part.split("\n");
@@ -81,6 +85,7 @@ export async function stream(url, data, handlers = {}, signal = undefined) {
}
if (terminal) break;
}
// Ohne explizites Abschluss- oder Fehlerereignis gilt die Verbindung als vorzeitig abgebrochen.
if (!terminal) throw new Error("Response was interrupted. Please try again.");
} finally {
await reader.cancel().catch(() => {});