Leichte Sprache: Arbeitsweise „Mit Prüfung“ mit Knopf in der Redaktion
- Neue Einstellung „Arbeitsweise“: „Mit Prüfung“ (Standard) oder „Automatisch für Leser“ - Knopf „Mit KI erstellen“ im Editor: Entwurf aus dem aktuellen, auch ungespeicherten Text (auch vor der Veröffentlichung der Meldung), live mit Abbrechen; Hinweis „KI-Entwurf – noch nicht veröffentlicht“; erst „Speichern“ macht ihn zur Fassung für Leser - Eingefügt wird nur die bereinigte Fassung (Server schickt sie am Ende des Streams), die rohe Modell-Ausgabe nie als HTML - Im Modus „Mit Prüfung“ lösen Leser keine KI aus, es gibt keine Hintergrund-Übertragung und Leser sehen nur geprüfte Texte - Im Modus „Automatisch“ zusätzlich „Zur Prüfung übernehmen“ - Datenschutz-Vorlage beschreibt beide Arbeitsweisen Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
c20f3a73d0
commit
a1e04773f4
14 changed files with 284 additions and 44 deletions
|
|
@ -15,8 +15,8 @@ Tablet und Desktop.
|
|||
- Termine & Schließzeiten, gruppiert nach Monat, mit Kalender-Abo (`/termine.ics`)
|
||||
- Ansprechpartner-Verzeichnis, Kontaktformular, Volltextsuche
|
||||
- **Barrierearm:** klare Schrift (Montserrat, selbst gehostet), 3 Schriftgrößen, Hell/Dunkel,
|
||||
**Leichte Sprache** pro Seite/Meldung – eigene geprüfte Fassung oder automatisch per KI übertragen
|
||||
(live beim ersten Aufruf bzw. vorab beim Speichern, gekennzeichnet, mit „Fehler melden“)
|
||||
**Leichte Sprache** pro Seite/Meldung – geprüfte Fassung (auch als KI-Entwurf erstellt) oder, wenn so
|
||||
eingestellt, automatisch per KI übertragen (gekennzeichnet, mit „Fehler melden“)
|
||||
- **Vorlesen** jeder Seite (Knopf in der Kopfzeile) oder eines Artikels: satzweise, der gelesene Satz
|
||||
wird markiert und mitgescrollt, mit Pause, Satz vor/zurück und langsamem Tempo
|
||||
- **Push-Benachrichtigungen** zu Neuigkeiten und Schließzeiten (Themen frei wählbar, jederzeit abbestellbar)
|
||||
|
|
@ -36,7 +36,8 @@ Tablet und Desktop.
|
|||
Startseiten-Bereiche, Mediathek, Postfach
|
||||
- Text-Editor mit Formatierungen, Links und Bildern
|
||||
- **Leichte Sprache per KI** (Einstellungen): Anbieter Anthropic (Claude), OpenAI, DeepSeek oder Ollama,
|
||||
Modell wählbar, Schlüssel verschlüsselt gespeichert, Verbindungstest, Tageslimit
|
||||
Modell wählbar, Schlüssel verschlüsselt gespeichert, Verbindungstest, Tageslimit. Arbeitsweise
|
||||
**„Mit Prüfung“** (Knopf „Mit KI erstellen“ → Entwurf prüfen → speichern) oder **„Automatisch für Leser“**
|
||||
- Bilder werden automatisch gedreht, verkleinert und als WebP gespeichert
|
||||
- **Benachrichtigungen:** beim Erscheinen einer Meldung (auch zeitgesteuert), automatisch am Vortag einer
|
||||
Schließzeit, oder von Hand – mit Vorschau und Verlauf
|
||||
|
|
|
|||
|
|
@ -58,12 +58,27 @@
|
|||
</script>
|
||||
|
||||
<div class="space-y-5">
|
||||
<Switch
|
||||
name="aiEnabled"
|
||||
checked={s.aiEnabled}
|
||||
label="Automatische Leichte Sprache einschalten"
|
||||
hint="Texte ohne eigene Fassung werden für Leser automatisch übertragen und gekennzeichnet."
|
||||
/>
|
||||
<Switch name="aiEnabled" checked={s.aiEnabled} label="Leichte Sprache mit KI einschalten" />
|
||||
|
||||
<fieldset>
|
||||
<legend class="label">Arbeitsweise</legend>
|
||||
<div class="space-y-2">
|
||||
<label class="flex items-start gap-3 rounded-2xl border-2 border-line p-3 cursor-pointer has-[:checked]:border-brand has-[:checked]:bg-brand-soft">
|
||||
<input type="radio" name="aiMode" value="review" checked={s.aiMode !== 'auto'} class="mt-1 accent-[var(--brand)]" />
|
||||
<span>
|
||||
<span class="block font-semibold">Mit Prüfung (empfohlen)</span>
|
||||
<span class="block text-sm text-ink-2">In der Redaktion erstellt „Mit KI erstellen“ einen Entwurf. Ihr prüft ihn und veröffentlicht mit „Speichern“. Leser sehen nur geprüfte Texte.</span>
|
||||
</span>
|
||||
</label>
|
||||
<label class="flex items-start gap-3 rounded-2xl border-2 border-line p-3 cursor-pointer has-[:checked]:border-brand has-[:checked]:bg-brand-soft">
|
||||
<input type="radio" name="aiMode" value="auto" checked={s.aiMode === 'auto'} class="mt-1 accent-[var(--brand)]" />
|
||||
<span>
|
||||
<span class="block font-semibold">Automatisch für Leser</span>
|
||||
<span class="block text-sm text-ink-2">Texte ohne geprüfte Fassung werden für Leser automatisch übertragen und gekennzeichnet – ohne Prüfung vorab. Der Knopf in der Redaktion bleibt.</span>
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<div class="grid sm:grid-cols-2 gap-4">
|
||||
<div>
|
||||
|
|
|
|||
|
|
@ -1,40 +1,161 @@
|
|||
<script lang="ts">
|
||||
import { untrack } from 'svelte';
|
||||
import { page } from '$app/state';
|
||||
import BookHeart from '@lucide/svelte/icons/book-heart';
|
||||
import ChevronDown from '@lucide/svelte/icons/chevron-down';
|
||||
import Sparkles from '@lucide/svelte/icons/sparkles';
|
||||
import Square from '@lucide/svelte/icons/square';
|
||||
import LoaderCircle from '@lucide/svelte/icons/loader-circle';
|
||||
import ClipboardCheck from '@lucide/svelte/icons/clipboard-check';
|
||||
import RichEditor from './RichEditor.svelte';
|
||||
import { toasts } from './toast.svelte';
|
||||
import { STREAM_DONE, STREAM_ERROR } from '$lib/easy-language';
|
||||
|
||||
type Auto = { enabled: boolean; html: string; fresh: boolean; at: string | null; model: string } | null;
|
||||
let { value = '', auto = null }: { value?: string; auto?: Auto } = $props();
|
||||
|
||||
let open = $state(untrack(() => !!value));
|
||||
let showAuto = $state(false);
|
||||
let editor = $state<ReturnType<typeof RichEditor>>();
|
||||
let root: HTMLElement;
|
||||
let busy = $state(false);
|
||||
let live = $state('');
|
||||
let confirmFor = $state<'' | 'ki' | 'auto'>('');
|
||||
let draft = $state(false);
|
||||
let controller: AbortController | null = null;
|
||||
|
||||
const aiReady = $derived(!!page.data.ai?.ready);
|
||||
const when = (iso: string) => new Date(iso).toLocaleString('de-DE', { dateStyle: 'short', timeStyle: 'short' });
|
||||
const words = $derived(live.replace(/<[^>]+>/g, ' ').trim().split(/\s+/).filter(Boolean).length);
|
||||
/** Live-Text nur als reiner Text – die rohe Modell-Ausgabe wird nie als HTML eingefügt */
|
||||
const liveText = $derived(
|
||||
live
|
||||
.replace(/<[^>]*$/, '')
|
||||
.replace(/<\/(p|h2|h3|li)>/g, '\n')
|
||||
.replace(/<li>/g, '• ')
|
||||
.replace(/<[^>]+>/g, '')
|
||||
.replace(/\n{2,}/g, '\n')
|
||||
.trim()
|
||||
);
|
||||
|
||||
/** Vor dem Ersetzen einer vorhandenen Fassung einmal nachfragen */
|
||||
function needsConfirm(kind: 'ki' | 'auto') {
|
||||
if (editor?.getHtml() && confirmFor !== kind) {
|
||||
confirmFor = kind;
|
||||
return true;
|
||||
}
|
||||
confirmFor = '';
|
||||
return false;
|
||||
}
|
||||
|
||||
function useDraft(html: string, message: string) {
|
||||
editor?.setContent(html);
|
||||
draft = true;
|
||||
open = true;
|
||||
toasts.show(message);
|
||||
}
|
||||
|
||||
function takeAuto() {
|
||||
if (!auto?.html || needsConfirm('auto')) return;
|
||||
useDraft(auto.html, 'Automatische Fassung übernommen – bitte prüfen und speichern');
|
||||
}
|
||||
|
||||
async function generate() {
|
||||
if (needsConfirm('ki')) return;
|
||||
const form = root.closest('form');
|
||||
const data = form ? new FormData(form) : new FormData();
|
||||
open = true;
|
||||
busy = true;
|
||||
live = '';
|
||||
controller = new AbortController();
|
||||
try {
|
||||
const res = await fetch('/admin/api/leichte-sprache', {
|
||||
method: 'POST',
|
||||
headers: { 'content-type': 'application/json' },
|
||||
body: JSON.stringify({ title: String(data.get('title') ?? ''), html: String(data.get('content') ?? '') }),
|
||||
signal: controller.signal
|
||||
});
|
||||
if (!res.ok || !res.body) {
|
||||
toasts.show((await res.json().catch(() => null))?.message ?? 'Die KI ist gerade nicht erreichbar.', 'error');
|
||||
return;
|
||||
}
|
||||
const reader = res.body.pipeThrough(new TextDecoderStream()).getReader();
|
||||
let text = '';
|
||||
for (;;) {
|
||||
const { value: chunk, done } = await reader.read();
|
||||
if (done) break;
|
||||
text += chunk;
|
||||
const cut = text.indexOf('\u0000');
|
||||
live = cut >= 0 ? text.slice(0, cut) : text;
|
||||
}
|
||||
const err = text.indexOf(STREAM_ERROR);
|
||||
if (err >= 0) {
|
||||
toasts.show(text.slice(err + STREAM_ERROR.length), 'error');
|
||||
return;
|
||||
}
|
||||
const fin = text.indexOf(STREAM_DONE);
|
||||
if (fin < 0) return; // abgebrochen
|
||||
useDraft(text.slice(fin + STREAM_DONE.length), 'KI-Entwurf eingefügt – bitte prüfen und speichern');
|
||||
} catch (e) {
|
||||
if ((e as Error).name !== 'AbortError') toasts.show('Die Verbindung zur KI ist abgebrochen.', 'error');
|
||||
} finally {
|
||||
busy = false;
|
||||
live = '';
|
||||
controller = null;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<section class="card overflow-hidden">
|
||||
<button type="button" class="w-full flex items-center gap-3 p-5 text-left" onclick={() => (open = !open)} aria-expanded={open}>
|
||||
<span class="grid place-items-center size-10 rounded-full bg-surface-2 text-brand-ink shrink-0" aria-hidden="true"><BookHeart class="size-5" /></span>
|
||||
<span class="flex-1">
|
||||
<span class="block text-lg font-bold">Leichte Sprache</span>
|
||||
<span class="block text-sm text-ink-3">
|
||||
{auto?.enabled
|
||||
? 'Optional: eigene, geprüfte Fassung. Ohne sie zeigt die App automatisch eine KI-Übertragung.'
|
||||
: 'Optional: eine einfache Fassung des Textes. Wird angezeigt, wenn Leser „Leichte Sprache“ einschalten.'}
|
||||
<section class="card overflow-hidden" bind:this={root}>
|
||||
<div class="flex flex-wrap items-center gap-3 p-5">
|
||||
<button type="button" class="flex flex-1 min-w-60 items-center gap-3 text-left" onclick={() => (open = !open)} aria-expanded={open}>
|
||||
<span class="grid place-items-center size-10 rounded-full bg-surface-2 text-brand-ink shrink-0" aria-hidden="true"><BookHeart class="size-5" /></span>
|
||||
<span class="flex-1">
|
||||
<span class="block text-lg font-bold">Leichte Sprache</span>
|
||||
<span class="block text-sm text-ink-3">
|
||||
{auto?.enabled
|
||||
? 'Geprüfte Fassung der Redaktion. Ohne sie zeigt die App automatisch eine KI-Übertragung.'
|
||||
: 'Fassung in Leichter Sprache. Wird angezeigt, wenn Leser „Leichte Sprache“ einschalten.'}
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
<ChevronDown class="size-5 text-ink-3 transition-transform {open ? 'rotate-180' : ''}" />
|
||||
</button>
|
||||
<ChevronDown class="size-5 text-ink-3 transition-transform {open ? 'rotate-180' : ''}" />
|
||||
</button>
|
||||
{#if aiReady}
|
||||
{#if busy}
|
||||
<button type="button" class="btn btn-soft btn-sm" onclick={() => controller?.abort()}><Square class="size-3.5" fill="currentColor" />Abbrechen</button>
|
||||
{:else}
|
||||
<button type="button" class="btn btn-accent btn-sm" onclick={generate} aria-describedby="ls-ki-hinweis">
|
||||
<Sparkles class="size-4" />{confirmFor === 'ki' ? 'Vorhandene Fassung ersetzen?' : 'Mit KI erstellen'}
|
||||
</button>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="px-5 pb-5 space-y-3" hidden={!open}>
|
||||
{#if auto?.enabled && !value}
|
||||
{#if busy}
|
||||
<div class="rounded-2xl border-2 border-dashed border-accent/50 bg-accent-soft/30 p-4" aria-busy="true">
|
||||
<p class="flex items-center gap-2 text-sm font-semibold text-accent-ink" role="status">
|
||||
<LoaderCircle class="size-4 animate-spin" aria-hidden="true" />
|
||||
{words ? `KI schreibt … ${words} Wörter` : 'KI liest den Text …'}
|
||||
</p>
|
||||
{#if liveText}<p class="mt-2 text-sm whitespace-pre-line text-ink-2 max-h-60 overflow-y-auto">{liveText}</p>{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if draft}
|
||||
<p class="text-sm rounded-xl bg-accent-soft text-accent-ink px-4 py-3" role="status">
|
||||
<strong>KI-Entwurf – noch nicht veröffentlicht.</strong> Bitte prüfen: Stimmen Fakten, Namen, Daten und Uhrzeiten? Ist jeder
|
||||
Satz verständlich? Erst mit „Speichern“ sehen Leser diese Fassung.
|
||||
</p>
|
||||
{/if}
|
||||
|
||||
{#if auto?.enabled && !value && !draft}
|
||||
<div class="rounded-xl bg-surface-2 px-4 py-3 text-sm space-y-2" role="status">
|
||||
<p class="flex items-start gap-2">
|
||||
<Sparkles class="size-4 mt-0.5 shrink-0 text-accent" aria-hidden="true" />
|
||||
<span>
|
||||
{#if auto.html && auto.fresh}
|
||||
Automatische Fassung vorhanden – erstellt am {when(auto.at!)} mit {auto.model}.
|
||||
Leser sehen gerade eine automatische Fassung – erstellt am {when(auto.at!)} mit {auto.model}.
|
||||
{:else if auto.html}
|
||||
Der Text wurde geändert. Die automatische Fassung wird beim Speichern bzw. beim nächsten Aufruf neu erstellt.
|
||||
{:else}
|
||||
|
|
@ -43,21 +164,28 @@
|
|||
</span>
|
||||
</p>
|
||||
{#if auto.html}
|
||||
<button type="button" class="text-sm font-semibold text-brand-ink underline underline-offset-2 min-h-6" aria-expanded={showAuto} onclick={() => (showAuto = !showAuto)}>
|
||||
{showAuto ? 'Automatische Fassung ausblenden' : 'Automatische Fassung ansehen'}
|
||||
</button>
|
||||
{#if showAuto}
|
||||
<div class="rich !text-base rounded-lg bg-surface p-4 border border-line">{@html auto.html}</div>
|
||||
<p class="hint !mt-0">Passt etwas nicht? Schreib unten eine eigene Fassung – sie hat dann Vorrang.</p>
|
||||
{/if}
|
||||
<div class="flex flex-wrap gap-x-4 gap-y-1">
|
||||
<button type="button" class="text-sm font-semibold text-brand-ink underline underline-offset-2 min-h-6" aria-expanded={showAuto} onclick={() => (showAuto = !showAuto)}>
|
||||
{showAuto ? 'Ausblenden' : 'Ansehen'}
|
||||
</button>
|
||||
<button type="button" class="inline-flex items-center gap-1 text-sm font-semibold text-brand-ink underline underline-offset-2 min-h-6" onclick={takeAuto}>
|
||||
<ClipboardCheck class="size-4" aria-hidden="true" />{confirmFor === 'auto' ? 'Vorhandene Fassung ersetzen?' : 'Zur Prüfung übernehmen'}
|
||||
</button>
|
||||
</div>
|
||||
{#if showAuto}<div class="rich !text-base rounded-lg bg-surface p-4 border border-line">{@html auto.html}</div>{/if}
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<RichEditor
|
||||
bind:this={editor}
|
||||
name="contentEasy"
|
||||
{value}
|
||||
label="Eigene Fassung in Leichter Sprache"
|
||||
label="Fassung in Leichter Sprache"
|
||||
hint="Tipps: kurze Sätze, ein Gedanke pro Satz, bekannte Wörter, lange Wörter mit Medio·punkt trennen."
|
||||
/>
|
||||
{#if aiReady}
|
||||
<p id="ls-ki-hinweis" class="hint">„Mit KI erstellen“ nimmt den aktuellen Text oben – auch ungespeichert – und schreibt einen Entwurf, den du hier prüfst.</p>
|
||||
{/if}
|
||||
</div>
|
||||
</section>
|
||||
|
|
|
|||
|
|
@ -1,2 +1,4 @@
|
|||
/** Markiert einen Fehler mitten im Stream der KI-Antwort (Server und Browser) */
|
||||
export const STREAM_ERROR = '\u0000FEHLER:';
|
||||
/** Danach folgt die bereinigte, endgültige Fassung (nur sie wird als HTML verwendet) */
|
||||
export const STREAM_DONE = '\u0000FERTIG:';
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { contacts, events, media, pages, posts, type Attachment, type Media, typ
|
|||
import { mediaUrl, thumbUrl } from './uploads';
|
||||
import type { AttachmentItem, ContactCard, EventItem, MediaItem, PageCard, PostCard } from '$lib/types';
|
||||
import { today } from '$lib/dates';
|
||||
import { isFresh, needsAuto } from './easy-auto';
|
||||
import { needsAuto, readerAuto } from './easy-auto';
|
||||
|
||||
export function toMediaItem(m: Media): MediaItem {
|
||||
return {
|
||||
|
|
@ -116,7 +116,7 @@ export function getPost(slug: string) {
|
|||
teaser: post.teaser,
|
||||
content: post.content,
|
||||
contentEasy: post.contentEasy,
|
||||
contentEasyAuto: isFresh(post) ? post.contentEasyAuto : '',
|
||||
contentEasyAuto: readerAuto(post),
|
||||
easyAutoPending: needsAuto(post),
|
||||
videoUrl: post.videoUrl,
|
||||
publishedAt: post.publishedAt.toISOString(),
|
||||
|
|
@ -170,7 +170,7 @@ export function getPage(slug: string) {
|
|||
color: page.color,
|
||||
content: page.content,
|
||||
contentEasy: page.contentEasy,
|
||||
contentEasyAuto: isFresh(page) ? page.contentEasyAuto : '',
|
||||
contentEasyAuto: readerAuto(page),
|
||||
easyAutoPending: needsAuto(page),
|
||||
cover: getMedia(page.coverId),
|
||||
attachments: attachmentsOf(page.attachments),
|
||||
|
|
|
|||
|
|
@ -93,9 +93,16 @@ function load(kind: EasyKind, id: number): Row | undefined {
|
|||
export const isFresh = (r: Pick<Row, 'title' | 'content' | 'contentEasyAuto' | 'contentEasyAutoHash'>) =>
|
||||
!!r.contentEasyAuto && r.contentEasyAutoHash === sourceHash(r.title, r.content);
|
||||
|
||||
/** Braucht der Text eine (neue) automatische Fassung? */
|
||||
/** Werden ungeprüfte KI-Fassungen an Leser ausgeliefert? (Modus „automatisch“) */
|
||||
export const autoForReaders = () => aiReady() && getSettings().aiMode === 'auto';
|
||||
|
||||
/** Braucht der Text eine (neue) automatische Fassung für Leser? */
|
||||
export const needsAuto = (r: Pick<Row, 'title' | 'content' | 'contentEasy' | 'contentEasyAuto' | 'contentEasyAutoHash'>) =>
|
||||
aiReady() && !r.contentEasy.trim() && !!htmlToStructuredText(r.content) && !isFresh(r);
|
||||
autoForReaders() && !r.contentEasy.trim() && !!htmlToStructuredText(r.content) && !isFresh(r);
|
||||
|
||||
/** Automatische Fassung, die Lesern gezeigt werden darf (nur im Modus „automatisch“) */
|
||||
export const readerAuto = (r: Pick<Row, 'title' | 'content' | 'contentEasyAuto' | 'contentEasyAutoHash'>) =>
|
||||
autoForReaders() && isFresh(r) ? r.contentEasyAuto : '';
|
||||
|
||||
// ─── Erzeugen ────────────────────────────────────────────────────────────────
|
||||
|
||||
|
|
@ -183,10 +190,34 @@ async function work() {
|
|||
/** Stand der automatischen Fassung für die Anzeige in der Redaktion */
|
||||
export function autoStatus(r: { title: string; content: string; contentEasyAuto: string; contentEasyAutoHash: string; contentEasyAutoModel: string; contentEasyAutoAt: Date | null }) {
|
||||
return {
|
||||
enabled: getSettings().aiEnabled,
|
||||
enabled: autoForReaders(),
|
||||
html: r.contentEasyAuto,
|
||||
fresh: isFresh(r),
|
||||
at: r.contentEasyAutoAt?.toISOString() ?? null,
|
||||
model: r.contentEasyAutoModel
|
||||
};
|
||||
}
|
||||
|
||||
// ─── Entwurf per Knopf in der Redaktion ──────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Entwurf aus dem (auch ungespeicherten) Text des Editors – wird nicht gespeichert,
|
||||
* sondern nach Prüfung von der Redaktion als eigene Fassung übernommen.
|
||||
*/
|
||||
export async function* streamDraft(title: string, html: string, signal?: AbortSignal): AsyncGenerator<string> {
|
||||
if (!aiReady()) throw new AiError('Die KI ist nicht eingerichtet (Einstellungen → Leichte Sprache mit KI).');
|
||||
const text = htmlToStructuredText(html);
|
||||
if (!text) throw new AiError('Bitte zuerst oben den normalen Text schreiben.');
|
||||
if (text.length > MAX_INPUT_CHARS) throw new AiError('Der Text ist zu lang. Bitte in kürzeren Abschnitten übertragen.');
|
||||
if (dailyUsage() >= getSettings().aiDailyLimit) throw new AiError('Das Tageslimit für KI-Übertragungen ist erreicht.');
|
||||
record('ki-tag');
|
||||
yield* streamText(
|
||||
currentConfig(),
|
||||
systemPrompt(getSettings().easyAddress),
|
||||
`Übertrage diesen Text in Leichte Sprache.\n\n<titel>${title}</titel>\n\n<text>\n${text}\n</text>`,
|
||||
signal
|
||||
);
|
||||
}
|
||||
|
||||
/** Modell-Ausgabe bereinigen (Code-Block entfernen, nur erlaubte Tags) */
|
||||
export const cleanDraft = (out: string) => cleanHtml(out.replace(/^\s*```(?:html)?\s*/i, '').replace(/```\s*$/, ''));
|
||||
|
|
|
|||
|
|
@ -64,11 +64,11 @@ export function privacyTemplate(s: AppSettings): string {
|
|||
'<p>Die Vorlesefunktion nutzt die Sprachausgabe deines Geräts. Wir bevorzugen Stimmen, die direkt auf dem Gerät arbeiten. Steht nur eine Online-Stimme des Browsers zur Verfügung, kann der vorgelesene Text vom Browser-Anbieter verarbeitet werden. Wir selbst erhalten dabei keine Daten.</p>',
|
||||
|
||||
s.aiEnabled
|
||||
? `<h2>7. Automatische Leichte Sprache</h2><p>Texte, die es noch nicht in Leichter Sprache gibt, überträgt eine KI automatisch. Dafür werden die veröffentlichten Texte der App an ${
|
||||
? `<h2>7. Leichte Sprache mit KI</h2><p>${s.aiMode === 'auto' ? 'Texte, die es noch nicht in Leichter Sprache gibt, überträgt eine KI automatisch. Dafür werden die veröffentlichten Texte der App' : 'Fassungen in Leichter Sprache entstehen mit Hilfe einer KI und werden vor der Veröffentlichung von der Redaktion geprüft. Dafür werden die Texte der App'} an ${
|
||||
s.aiProvider === 'ollama'
|
||||
? 'einen KI-Dienst auf einem eigenen Server des Verantwortlichen'
|
||||
: `den Anbieter ${esc(AI_PROVIDERS[s.aiProvider].label)} (Verarbeitung auch außerhalb der EU möglich, auf Grundlage eines Auftragsverarbeitungsvertrags)`
|
||||
} übermittelt. Von dir als Leserin oder Leser werden dabei keine Daten übermittelt. Automatisch übertragene Texte sind in der App gekennzeichnet.</p>`
|
||||
} übermittelt. Von dir als Leserin oder Leser werden dabei keine Daten übermittelt.${s.aiMode === 'auto' ? ' Automatisch übertragene Texte sind in der App gekennzeichnet.' : ''}</p>`
|
||||
: '',
|
||||
`<h2>${s.aiEnabled ? 8 : 7}. Eingebettete Videos</h2>`,
|
||||
'<p>Videos von YouTube (im erweiterten Datenschutzmodus, youtube-nocookie.com) oder Vimeo werden erst geladen, wenn du auf „Video abspielen“ tippst. Erst dann wird eine Verbindung zum jeweiligen Anbieter hergestellt, der dabei u. a. deine IP-Adresse erhält und Daten auch in den USA verarbeiten kann (Einwilligung, Art. 6 Abs. 1 lit. a DSGVO).</p>',
|
||||
|
|
|
|||
|
|
@ -62,8 +62,10 @@ export type AppSettings = {
|
|||
/** Wie viele Meldungen/Termine die Startseite zeigt */
|
||||
/** Administratoren müssen die Zwei-Faktor-Anmeldung einrichten */
|
||||
require2faAdmins: boolean;
|
||||
/** Automatische Leichte Sprache per KI für Leser */
|
||||
/** Leichte Sprache per KI eingeschaltet */
|
||||
aiEnabled: boolean;
|
||||
/** review = Entwurf per Knopf, Redaktion prüft; auto = automatisch für Leser */
|
||||
aiMode: 'review' | 'auto';
|
||||
aiProvider: AiProvider;
|
||||
aiModel: string;
|
||||
/** Adresse des Dienstes (Ollama oder eigener Endpunkt), leer = Standard des Anbieters */
|
||||
|
|
@ -115,6 +117,7 @@ export const DEFAULT_SETTINGS: AppSettings = {
|
|||
},
|
||||
require2faAdmins: false,
|
||||
aiEnabled: false,
|
||||
aiMode: 'review',
|
||||
aiProvider: 'anthropic',
|
||||
aiModel: '',
|
||||
aiBaseUrl: '',
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
import { eq, sql } from 'drizzle-orm';
|
||||
import { db } from '$lib/server/db';
|
||||
import { messages } from '$lib/server/db/schema';
|
||||
import { aiReady } from '$lib/server/ai';
|
||||
import { getSettings } from '$lib/server/settings';
|
||||
|
||||
export const load = ({ locals }) => ({
|
||||
user: locals.user!,
|
||||
ai: { ready: aiReady(), mode: getSettings().aiMode },
|
||||
unread: db.select({ n: sql<number>`count(*)` }).from(messages).where(eq(messages.read, false)).get()?.n ?? 0
|
||||
});
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ function read(form: FormData): Partial<AppSettings> | string {
|
|||
require2faAdmins: f.bool('require2faAdmins'),
|
||||
easyAddress: f.str('easyAddress') === 'Sie' ? 'Sie' : 'du',
|
||||
aiEnabled: f.bool('aiEnabled'),
|
||||
aiMode: f.str('aiMode') === 'auto' ? 'auto' : 'review',
|
||||
aiProvider: (f.str('aiProvider') in AI_PROVIDERS ? f.str('aiProvider') : 'anthropic') as AiProvider,
|
||||
aiModel: f.str('aiModel', 120),
|
||||
aiBaseUrl: f.str('aiBaseUrl', 300),
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ export const load = ({ params }) => {
|
|||
if (id === 'new') {
|
||||
return {
|
||||
isNew: true,
|
||||
easyAuto: { enabled: getSettings().aiEnabled, html: '', fresh: false, at: null, model: '' } as ReturnType<typeof autoStatus>,
|
||||
easyAuto: { enabled: getSettings().aiEnabled && getSettings().aiMode === 'auto', html: '', fresh: false, at: null, model: '' } as ReturnType<typeof autoStatus>,
|
||||
subscribers: subscriberCounts().byTopic.news,
|
||||
contactOptions,
|
||||
post: {
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ export const load = ({ params, url }) => {
|
|||
const parent = Number(url.searchParams.get('parent')) || null;
|
||||
return {
|
||||
isNew: true, contactOptions, parentOptions,
|
||||
easyAuto: { enabled: getSettings().aiEnabled, html: '', fresh: false, at: null, model: '' } as ReturnType<typeof autoStatus>,
|
||||
easyAuto: { enabled: getSettings().aiEnabled && getSettings().aiMode === 'auto', html: '', fresh: false, at: null, model: '' } as ReturnType<typeof autoStatus>,
|
||||
page: {
|
||||
id: 0, parentId: parent, title: '', slug: '', teaser: '', icon: 'file-text', color: 'sky', content: '', contentEasy: '',
|
||||
published: true, cover: null as MediaItem | null, attachments: [] as ReturnType<typeof attachmentsOf>, contactIds: [] as number[]
|
||||
|
|
|
|||
55
src/routes/admin/api/leichte-sprache/+server.ts
Normal file
55
src/routes/admin/api/leichte-sprache/+server.ts
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import { error } from '@sveltejs/kit';
|
||||
import { allow } from '$lib/server/ratelimit';
|
||||
import { AiError } from '$lib/server/ai';
|
||||
import { cleanDraft, streamDraft } from '$lib/server/easy-auto';
|
||||
import { STREAM_DONE, STREAM_ERROR } from '$lib/easy-language';
|
||||
|
||||
/**
|
||||
* Knopf „Mit KI erstellen“ in der Redaktion: streamt einen Entwurf aus dem
|
||||
* aktuellen Text. Gespeichert wird erst, wenn die Redaktion ihn geprüft hat.
|
||||
*/
|
||||
export const POST = async ({ request, locals }) => {
|
||||
if (!allow(`ki-entwurf:${locals.user!.id}`, 30, 3600e3)) error(429, 'Zu viele Anfragen. Bitte warte etwas.');
|
||||
const body = await request.json().catch(() => null);
|
||||
const title = typeof body?.title === 'string' ? body.title.slice(0, 300) : '';
|
||||
const html = typeof body?.html === 'string' ? body.html : '';
|
||||
|
||||
const generator = streamDraft(title, html, request.signal);
|
||||
// Ersten Abschnitt abwarten, damit Eingabefehler als normaler Fehler-Status ankommen
|
||||
let first: IteratorResult<string>;
|
||||
try {
|
||||
first = await generator.next();
|
||||
} catch (e) {
|
||||
error(400, e instanceof AiError ? e.message : 'Die KI ist gerade nicht erreichbar.');
|
||||
}
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
const stream = new ReadableStream<Uint8Array>({
|
||||
async start(controller) {
|
||||
let out = '';
|
||||
try {
|
||||
if (!first.done) {
|
||||
out += first.value;
|
||||
controller.enqueue(encoder.encode(first.value));
|
||||
}
|
||||
for await (const chunk of generator) {
|
||||
out += chunk;
|
||||
controller.enqueue(encoder.encode(chunk));
|
||||
}
|
||||
const clean = cleanDraft(out);
|
||||
controller.enqueue(encoder.encode(clean ? STREAM_DONE + clean : STREAM_ERROR + 'Die KI hat keinen Text geliefert.'));
|
||||
} catch (e) {
|
||||
const name = (e as Error)?.name ?? '';
|
||||
if (name !== 'APIUserAbortError' && name !== 'AbortError')
|
||||
controller.enqueue(encoder.encode(STREAM_ERROR + (e instanceof AiError ? e.message : 'Unerwarteter Fehler bei der KI.')));
|
||||
}
|
||||
controller.close();
|
||||
},
|
||||
cancel() {
|
||||
generator.return(undefined);
|
||||
}
|
||||
});
|
||||
return new Response(stream, {
|
||||
headers: { 'Content-Type': 'text/plain; charset=utf-8', 'Cache-Control': 'no-store', 'X-Accel-Buffering': 'no' }
|
||||
});
|
||||
};
|
||||
|
|
@ -3,7 +3,7 @@ import { and, eq, lte } from 'drizzle-orm';
|
|||
import { db } from '$lib/server/db';
|
||||
import { pages, posts } from '$lib/server/db/schema';
|
||||
import { AiError } from '$lib/server/ai';
|
||||
import { generate, isFresh, needsAuto, type EasyKind } from '$lib/server/easy-auto';
|
||||
import { generate, needsAuto, readerAuto, type EasyKind } from '$lib/server/easy-auto';
|
||||
import { allow } from '$lib/server/ratelimit';
|
||||
import { STREAM_ERROR } from '$lib/easy-language';
|
||||
|
||||
|
|
@ -29,7 +29,8 @@ export const POST = async ({ request, getClientAddress }) => {
|
|||
const row = find(kind, slug);
|
||||
if (!row) error(404, 'Text nicht gefunden.');
|
||||
if (row.contentEasy.trim()) return json({ html: row.contentEasy, auto: false });
|
||||
if (isFresh(row)) return json({ html: row.contentEasyAuto, auto: true });
|
||||
const ready = readerAuto(row);
|
||||
if (ready) return json({ html: ready, auto: true });
|
||||
if (!needsAuto(row)) error(503, 'Leichte Sprache ist für diesen Text gerade nicht verfügbar.');
|
||||
|
||||
// Kostenschutz: pro Gerät höchstens 20 neue Übertragungen pro Stunde
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue