Files
wibosim/server/src/kisave.js
T
db9979andClaude Opus 5.5 298e59598f Werkstatt: KI-Zustände überstehen Neustart, Probelauf mit Ablehnungsstatistik, Ton und Länge je Funktion
- Coach (Tagesnotizen, Stopp-Erklärungen, Antworten) und Leitstand (Zusammenfassung, Entwürfe) als eigene Meta-Einträge gespeichert, gebündelt geschrieben, alte Einträge aufgeräumt
- llmhub: optionale Begründung validate(obj, why), Zählung getrennt nach abgelehnt/unbrauchbar/Ausfall, Beispiel-Erzeuger je Zweck, probe() am Budget vorbei
- KI-Leitstand: Probelauf mit Vorlage, Rohantwort, geprüftem Text bzw. Grund, Dauer und Prompt; Ablehnungsstatistik je Zweck
- Einstellungsgruppe KI-Stil: Ton, Länge, Stilwunsch je Funktion; Rundungs-Toleranz der Zahlenprüfung in press.js

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018i4GUhQVoPUusUzxgxLWkK
2026-12-05 08:04:01 +00:00

37 lines
1.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Werkstatt: sparsames Speichern kleiner KI-Zustände (Coach-Notizen und -Antworten, Leitstand) als eigener
// Meta-Eintrag in der Datenbank. Geschrieben wird nur nach einer Änderung und gebündelt (Verzögerung), damit der
// Raspberry Pi nicht bei jeder Antwort schreibt; saveNow() schreibt sofort (Herunterfahren, Handelsschluss).
export class KiSaver {
/**
* @param {object} o store (metaGet/metaPut), key (Meta-Schlüssel), snapshot () => Daten, delayMs,
* alive () => boolean (false: Modul wurde ersetzt, z. B. nach Wiederherstellen einer Sicherung – nicht mehr schreiben)
*/
constructor({ store, key, snapshot, delayMs = 5000, alive = () => true }) {
Object.assign(this, { store, key, snapshot, delayMs, alive });
this.dirty = false;
this.timer = null;
}
/** gespeicherten Stand lesen (null, wenn es keinen gibt oder die Datenbank fehlt) */
load() {
try { return this.store?.metaGet?.(this.key) ?? null; } catch { return null; }
}
/** Änderung vormerken; geschrieben wird gebündelt nach delayMs */
mark() {
this.dirty = true;
if (this.timer || !this.store?.metaPut) return;
this.timer = setTimeout(() => { this.timer = null; this.saveNow(); }, this.delayMs);
this.timer.unref?.();
}
saveNow() {
if (this.timer) { clearTimeout(this.timer); this.timer = null; }
if (!this.dirty || !this.store?.metaPut) return false;
if (!this.alive()) { this.dirty = false; return false; }
this.dirty = false;
try { this.store.metaPut(this.key, this.snapshot()); return true; } catch (e) { console.warn(`[${this.key}] speichern`, e.message); return false; }
}
}