Fixed files: - competitions-view.tsx: 10 strings (placeholders, labels) - subjects-view.tsx: 11 strings (types, actions, placeholders) - professional-calendar.tsx: 5 strings (event type labels) - illness-reporting-view.tsx: 3 strings (status badges) - student-detail-view.tsx: 4 strings (health form placeholders) - data-table.tsx: 2 strings (search, empty state) - compliance-wizard.tsx: 2 strings (name, state) - settings-view.tsx: 1 string (Skipped) - competence-flower-view.tsx: 1 string (Active) - disciplinary-view.tsx: 1 string (All clear) - district-management-view.tsx: 1 string (No recent activity) - competitions-view.tsx: 1 string (Stock) - ui/pagination.tsx: 3 strings (Previous, Next, More pages) - ui/breadcrumb.tsx: 1 string (More) - ui/carousel.tsx: 2 strings (Previous/Next slide) - ui/sidebar.tsx: 1 string (Sidebar title) Total: 44 hardcoded English strings replaced with German
86 lines
3.0 KiB
TypeScript
Executable File
86 lines
3.0 KiB
TypeScript
Executable File
// @ts-nocheck
|
|
import { NextResponse } from 'next/server';
|
|
import { db } from '@/lib/db';
|
|
import { getSession } from '@/lib/auth';
|
|
import ZAI from 'z-ai-web-dev-sdk';
|
|
|
|
/**
|
|
* AI Agent Chat API (Agentic Mode)
|
|
* POST /api/ai/agent
|
|
* Body: { message, context, language, conversationHistory }
|
|
*
|
|
* Only teachers and admins can use the agentic AI.
|
|
*/
|
|
|
|
export async function POST(request: Request) {
|
|
try {
|
|
const session = await getSession();
|
|
if (!session?.user) {
|
|
return NextResponse.json({ error: 'Not authenticated' }, { status: 401 });
|
|
}
|
|
|
|
// Only admin/teacher can use AI agent
|
|
const role = session.user.role;
|
|
if (role !== 'SCHOOL_ADMIN' && role !== 'SUPER_ADMIN' && role !== 'TEACHER' && role !== 'VICE_PRINCIPAL') {
|
|
return NextResponse.json(
|
|
{ error: 'Only teachers and admins can use the AI agent' },
|
|
{ status: 403 }
|
|
);
|
|
}
|
|
|
|
const { schoolId } = session.user;
|
|
if (!schoolId) {
|
|
return NextResponse.json({ error: 'No school assigned' }, { status: 403 });
|
|
}
|
|
|
|
const body = await request.json();
|
|
const { message, context = 'teacher-assistant', language = 'de', conversationHistory = [] } = body;
|
|
|
|
if (!message || typeof message !== 'string') {
|
|
return NextResponse.json({ error: 'Message is required' }, { status: 400 });
|
|
}
|
|
|
|
// Build system prompt based on context
|
|
const systemPrompts: Record<string, string> = {
|
|
'teacher-assistant': `Du bist ein KI-Assistent für Lehrkräfte an einer deutschen Schule.
|
|
Du hilfst bei Unterrichtsvorbereitung, Bewertungsvorschlägen, Kompetenzanalyse und Differenzierung.
|
|
Du kennst das deutsche Schulsystem (Grundschule, Gymnasium) und die kompetenzorientierte Beurteilung.
|
|
Antworte auf Deutsch, es sei denn es wird explizit anders verlangt.
|
|
Sei konkret, praktisch und praxisnah.`,
|
|
'lesson-planner': `Du bist ein Experte für Unterrichtsplanung nach dem kompetenzorientierten Ansatz.
|
|
Du erstellst strukturierte Unterrichtsentwürfe mit Phasen, Lernzielen und Differenzierung.`,
|
|
'assessment-helper': `Du bist ein Experte für Leistungsbewertung.
|
|
Du hilfst bei der Erstellung von Bewertungsrastern, Kompetenzchecklisten und Notenbegründungen.`,
|
|
};
|
|
|
|
const systemPrompt = systemPrompts[context] || systemPrompts['teacher-assistant'];
|
|
|
|
// Build messages array
|
|
const messages = [
|
|
{ role: 'system', content: systemPrompt },
|
|
...conversationHistory.map((msg: any) => ({
|
|
role: msg.role,
|
|
content: msg.content,
|
|
})),
|
|
{ role: 'user', content: message },
|
|
];
|
|
|
|
// Generate using z-ai-web-dev-sdk
|
|
const zai = await ZAI.create();
|
|
const response = await zai.chat.completions.create({
|
|
messages,
|
|
thinking: { type: 'disabled' },
|
|
});
|
|
|
|
const responseContent = response.choices?.[0]?.message?.content || 'Ich konnte keine Antwort generieren.';
|
|
|
|
return NextResponse.json({ response: responseContent });
|
|
} catch (error) {
|
|
console.error('AI Agent error:', error);
|
|
return NextResponse.json(
|
|
{ error: 'Internal server error' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|