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:
Friederich Loheide 2026-10-03 06:01:46 +00:00
parent c20f3a73d0
commit a1e04773f4
14 changed files with 284 additions and 44 deletions

View file

@ -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
});

View file

@ -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),

View file

@ -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: {

View file

@ -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[]

View 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' }
});
};

View file

@ -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