feat: Complete AI Chat Agent, Admin Settings (MCP/AI), and Translations
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-12-15 21:52:36 +01:00
parent 71d5c825c5
commit 9736864425
24 changed files with 1679 additions and 401 deletions
+7
View File
@@ -33,6 +33,7 @@ import { useTimer } from './hooks/useTimer';
import { Plus } from 'lucide-react';
import { SidebarProvider, SidebarInset, SidebarTrigger } from "@/components/ui/sidebar"
import { AppSidebar } from "./components/AppSidebar"
import { useNotifications } from './hooks/use-notifications';
import { CommandPalette } from './components/CommandPalette';
import PomodoroOverlay from './components/PomodoroOverlay';
import AuthPage from "@/pages/AuthPage";
@@ -46,6 +47,8 @@ import { AiChat } from "@/components/AiChat";
import ForgotPasswordPage from "@/pages/ForgotPasswordPage";
import ResetPasswordPage from "@/pages/ResetPasswordPage";
import AiChatPage from "@/pages/AiChatPage";
import FocusRoutinePage from "@/pages/FocusRoutinePage";
import { useQuery, useQueryClient } from "@tanstack/react-query";
import { User } from "@shared/schema";
@@ -63,6 +66,9 @@ function App() {
const [showPomodoro, setShowPomodoro] = useState(false);
const [activePomodoroTaskId, setActivePomodoroTaskId] = useState<string | null>(null);
// Enable global notifications polling
useNotifications({ poll: true });
const queryClient = useQueryClient();
const { data: user, isLoading: isLoadingUser } = useQuery<User>({
@@ -381,6 +387,7 @@ function App() {
</>
)}
<Route path="/focus/routine/:type" component={FocusRoutinePage} />
<Route component={NotFound} />
</Switch>
</main>
+29 -7
View File
@@ -4,7 +4,7 @@ import { Task } from '@shared/schema';
import TaskCard from './TaskCard';
import { Card } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
import { Trophy, Target, Calendar as CalendarIcon, ArrowRight, GripVertical } from 'lucide-react';
import { Trophy, Target, Calendar as CalendarIcon, ArrowRight, GripVertical, Sun, Moon } from 'lucide-react';
import { motion, AnimatePresence } from 'framer-motion';
import {
DndContext,
@@ -190,13 +190,35 @@ export default function FocusMode({
initial={{ opacity: 0, scale: 0.95 }}
animate={{ opacity: 1, scale: 1 }}
transition={{ delay: 0.2 }}
className="grid grid-rows-2 gap-4 h-full"
>
<Card className="p-6 h-full flex flex-col justify-center items-center text-center bg-card hover:shadow-md transition-all cursor-pointer" onClick={onNavigateToTasks}>
<Target className="w-12 h-12 text-muted-foreground/20 mb-4" />
<h3 className="font-semibold text-lg">{t('focus.viewAll.title')}</h3>
<p className="text-sm text-muted-foreground mb-4">{t('focus.viewAll.description')}</p>
<Button variant="outline" className="gap-2 group">
{t('focus.viewAll.button')} <ArrowRight className="w-4 h-4 group-hover:translate-x-1 transition-transform" />
{/* Routine Actions */}
<div className="grid grid-cols-2 gap-4">
<Button
variant="outline"
className="h-full flex flex-col items-center justify-center gap-2 hover:bg-orange-50 hover:text-orange-600 dark:hover:bg-orange-950/30 border-dashed"
onClick={() => window.location.href = '/focus/routine/morning'}
>
<Sun className="w-5 h-5 text-orange-500" />
<span className="text-xs font-semibold">{t('focus.routine.morning', 'Morning Plan')}</span>
</Button>
<Button
variant="outline"
className="h-full flex flex-col items-center justify-center gap-2 hover:bg-indigo-50 hover:text-indigo-600 dark:hover:bg-indigo-950/30 border-dashed"
onClick={() => window.location.href = '/focus/routine/evening'}
>
<Moon className="w-5 h-5 text-indigo-500" />
<span className="text-xs font-semibold">{t('focus.routine.evening', 'Evening Review')}</span>
</Button>
</div>
<Card className="p-4 flex flex-col justify-center items-center text-center bg-card hover:shadow-md transition-all cursor-pointer" onClick={onNavigateToTasks}>
<div className="flex items-center gap-2 mb-2">
<Target className="w-5 h-5 text-muted-foreground/50" />
<h3 className="font-semibold text-sm">{t('focus.viewAll.title')}</h3>
</div>
<Button variant="ghost" size="sm" className="gap-1 text-xs text-muted-foreground group">
{t('focus.viewAll.button')} <ArrowRight className="w-3 h-3 group-hover:translate-x-1 transition-transform" />
</Button>
</Card>
</motion.div>
+57
View File
@@ -31,6 +31,10 @@ import { triggerConfetti } from "@/lib/confetti";
import { playSuccessSound } from "@/lib/sounds";
import { simulateAIDecomposition } from "@/lib/ai-simulator";
import { Wand2, Loader2 } from "lucide-react";
import { apiRequest } from "@/lib/queryClient";
import { useToast } from "@/hooks/use-toast";
interface TaskCardProps {
task: Task;
@@ -120,6 +124,7 @@ function SharedMenuItem({ task, onShare }: { task: Task, onShare: () => void })
export default function TaskCard({ task, onStartTimer, onStopTimer, onEdit, onDelete, onStatusChange, onUpdate, isDragging }: TaskCardProps) {
const { t } = useTranslation();
const { toast } = useToast();
const [isAnalyzing, setIsAnalyzing] = useState(false);
const [isShareModalOpen, setIsShareModalOpen] = useState(false);
@@ -201,6 +206,56 @@ export default function TaskCard({ task, onStartTimer, onStopTimer, onEdit, onDe
return `${hours}h ${mins}m`;
};
/* AI Follow-up Check */
const checkFollowUp = async () => {
// Fire and forget - don't block UI
try {
const res = await apiRequest("POST", "/api/ai/analyze-completion", { taskId: task.id });
if (res.ok) {
const data = await res.json();
if (data.needed && data.title) {
toast({
title: t('ai.followUpSuggestion', 'Follow-up Suggested'),
description: `${data.title} - ${data.description || ''}`,
action: (
<Button
variant="outline"
size="sm"
onClick={async (e) => {
e.stopPropagation(); // prevent toast click from doing generic things
// Create the task immediately
try {
await apiRequest("POST", "/api/tasks", {
title: data.title,
description: data.description,
status: "todo",
priority: "medium",
labelId: task.labelId, // Inherit label
dueDate: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString() // Tomorrow
});
toast({ title: t('ai.taskCreated', 'Follow-up task created!') });
// Invalidate queries to show new task
// queryClient.invalidateQueries... (Need queryClient access)
// Since we don't have queryClient here easily without import useQueryClient
// We can just reload or rely on auto-refetch
window.location.reload(); // Crude but effective for now, or useQueryClient
} catch (err) {
toast({ title: t('ai.errorCreating', 'Failed to create task'), variant: "destructive" });
}
}}
>
{t('common.create', 'Create')}
</Button>
),
duration: 8000,
});
}
}
} catch (e) {
console.error("Follow-up check failed", e);
}
};
const handleToggleComplete = (e: React.MouseEvent) => {
e.stopPropagation();
if (isBlocked) return;
@@ -210,6 +265,8 @@ export default function TaskCard({ task, onStartTimer, onStopTimer, onEdit, onDe
triggerConfetti(e.clientX / window.innerWidth, e.clientY / window.innerHeight);
playSuccessSound();
onStatusChange?.('done');
// Trigger AI check
checkFollowUp();
}
};
@@ -38,6 +38,12 @@ export default function TaskCreationModal({ isOpen, onClose, onSave }: TaskCreat
const [isCalendarOpen, setIsCalendarOpen] = useState(false);
const [isStartDateOpen, setIsStartDateOpen] = useState(false);
const [isRecurring, setIsRecurring] = useState(false);
const [recurrenceInterval, setRecurrenceInterval] = useState<string | undefined>();
const [recurrenceIntervalValue, setRecurrenceIntervalValue] = useState(1);
const [recurrenceEnd, setRecurrenceEnd] = useState<Date | undefined>();
const [error, setError] = useState<string | null>(null);
// Fetch labels
@@ -62,6 +68,11 @@ export default function TaskCreationModal({ isOpen, onClose, onSave }: TaskCreat
energyLevel,
estimatedDuration,
isRecurring,
recurrenceInterval,
recurrenceIntervalValue,
recurrenceEnd,
startDate,
dueDate,
labelId,
@@ -80,6 +91,10 @@ export default function TaskCreationModal({ isOpen, onClose, onSave }: TaskCreat
setPriority('medium');
setDueDate(undefined);
setStartDate(undefined);
setIsRecurring(false);
setRecurrenceInterval(undefined);
setRecurrenceIntervalValue(1);
setRecurrenceEnd(undefined);
setLabelId(undefined);
setDependencies([]);
setError(null);
@@ -99,6 +114,10 @@ export default function TaskCreationModal({ isOpen, onClose, onSave }: TaskCreat
setPriority('medium');
setDueDate(undefined);
setStartDate(undefined);
setIsRecurring(false);
setRecurrenceInterval(undefined);
setRecurrenceIntervalValue(1);
setRecurrenceEnd(undefined);
setLabelId(undefined);
setDependencies([]);
setError(null);
@@ -283,6 +302,42 @@ export default function TaskCreationModal({ isOpen, onClose, onSave }: TaskCreat
</div>
</div>
{/* Recurrence Selection */}
<div className="flex items-center gap-2">
<label className="text-sm font-medium flex-none">{t('taskCreation.recurrence.label')}</label>
<Select value={recurrenceInterval || 'none'} onValueChange={(v) => {
setRecurrenceInterval(v === 'none' ? undefined : v);
setIsRecurring(v !== 'none');
}}>
<SelectTrigger className="h-8">
<SelectValue placeholder={t('taskCreation.recurrence.none')} />
</SelectTrigger>
<SelectContent>
<SelectItem value="none">{t('taskCreation.recurrence.none')}</SelectItem>
<SelectItem value="daily">{t('taskCreation.recurrence.daily')}</SelectItem>
<SelectItem value="weekly">{t('taskCreation.recurrence.weekly')}</SelectItem>
<SelectItem value="monthly">{t('taskCreation.recurrence.monthly')}</SelectItem>
<SelectItem value="yearly">{t('taskCreation.recurrence.yearly')}</SelectItem>
</SelectContent>
</Select>
{isRecurring && (
<div className="flex items-center gap-2 animate-in fade-in slide-in-from-left-2">
<span className="text-sm">{t('taskCreation.recurrence.every')}</span>
<Input
type="number"
className="w-16 h-8"
min={1}
value={recurrenceIntervalValue}
onChange={(e) => setRecurrenceIntervalValue(parseInt(e.target.value) || 1)}
/>
<span className="text-sm">
{recurrenceInterval && t(`taskCreation.recurrence.units.${recurrenceInterval}`)}
</span>
</div>
)}
</div>
{/* Dependencies Selector */}
<div className="space-y-2">
<label className="text-sm font-medium flex items-center gap-2">
+27 -8
View File
@@ -4,6 +4,7 @@ import { useQuery, useMutation } from "@tanstack/react-query";
import { Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter } from "@/components/ui/card";
import { Label } from "@/components/ui/label";
import { Input } from "@/components/ui/input";
import { Textarea } from "@/components/ui/textarea";
import { Button } from "@/components/ui/button";
import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from "@/components/ui/select";
import { Loader2, Bot, RefreshCw, Download, Server } from "lucide-react";
@@ -25,6 +26,7 @@ export function AiSettingsCard() {
const [apiKey, setApiKey] = useState("");
const [model, setModel] = useState("gpt-4o");
const [baseUrl, setBaseUrl] = useState("");
const [systemPrompt, setSystemPrompt] = useState("");
// Ollama specific state
const [ollamaModels, setOllamaModels] = useState<string[]>([]);
@@ -36,6 +38,7 @@ export function AiSettingsCard() {
setApiKey(settings.ai_api_key || "");
setModel(settings.ai_model || "gpt-4o");
setBaseUrl(settings.ai_base_url || "");
setSystemPrompt(settings.ai_system_prompt || "");
}
}, [settings]);
@@ -46,10 +49,10 @@ export function AiSettingsCard() {
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['/api/admin/settings'] });
toast({ title: "Settings saved" });
toast({ title: t('settings.ai.saved', "Settings saved") });
},
onError: () => {
toast({ title: "Failed to save settings", variant: "destructive" });
toast({ title: t('settings.ai.error', "Failed to save settings"), variant: "destructive" });
}
});
@@ -62,10 +65,10 @@ export function AiSettingsCard() {
onSuccess: (data: any) => {
const models = data.models?.map((m: any) => m.name) || [];
setOllamaModels(models);
toast({ title: `Found ${models.length} models` });
toast({ title: t('settings.ai.ollama.found', { count: models.length }) });
},
onError: (err: Error) => {
toast({ title: "Could not connect to Ollama", description: err.message, variant: "destructive" });
toast({ title: t('settings.ai.ollama.connectError', "Could not connect to Ollama"), description: err.message, variant: "destructive" });
}
});
@@ -76,12 +79,12 @@ export function AiSettingsCard() {
return res.json();
},
onSuccess: () => {
toast({ title: "Model pulled successfully" });
toast({ title: t('settings.ai.ollama.pullSuccess', "Model pulled successfully") });
setPullModelName("");
fetchOllamaModelsMutation.mutate(); // Refresh list
},
onError: (err: Error) => {
toast({ title: "Failed to pull model", description: err.message, variant: "destructive" });
toast({ title: t('settings.ai.ollama.pullError', "Failed to pull model"), description: err.message, variant: "destructive" });
}
});
@@ -91,7 +94,8 @@ export function AiSettingsCard() {
ai_provider: provider,
ai_api_key: apiKey,
ai_model: model,
ai_base_url: baseUrl
ai_base_url: baseUrl,
ai_system_prompt: systemPrompt
});
};
@@ -136,7 +140,7 @@ export function AiSettingsCard() {
type="password"
value={apiKey}
onChange={(e) => setApiKey(e.target.value)}
placeholder={provider === 'ollama' ? 'Optional for Ollama' : 'sk-...'}
placeholder={provider === 'ollama' ? t('settings.ai.ollama.placeholder', 'Optional for Ollama') : 'sk-...'}
/>
</div>
@@ -217,6 +221,21 @@ export function AiSettingsCard() {
</div>
)}
<div className="grid gap-2 pt-4 border-t">
<Label className="flex items-center justify-between">
{t('settings.ai.systemPrompt', 'System Prompt')}
<span className="text-xs text-muted-foreground font-normal">
Available: {"${user.username}"}, {"${currentDate...}"}, {"${context}"}
</span>
</Label>
<Textarea
className="font-mono text-sm min-h-[300px]"
value={systemPrompt}
onChange={(e) => setSystemPrompt(e.target.value)}
placeholder="You are TaskFlow AI..."
/>
</div>
</CardContent>
<CardFooter>
<Button onClick={handleSave} disabled={mutation.isPending}>
@@ -42,18 +42,18 @@ export function AuditLogsTable() {
return (
<Card>
<CardHeader>
<CardTitle>Audit Logs</CardTitle>
<CardDescription>Track all system changes and AI actions.</CardDescription>
<CardTitle>{t('settings.auditLogs.title')}</CardTitle>
<CardDescription>{t('settings.auditLogs.description')}</CardDescription>
</CardHeader>
<CardContent>
<Table>
<TableHeader>
<TableRow>
<TableHead>Time</TableHead>
<TableHead>Source</TableHead>
<TableHead>Action</TableHead>
<TableHead>Entity</TableHead>
<TableHead>Details</TableHead>
<TableHead>{t('settings.auditLogs.table.time')}</TableHead>
<TableHead>{t('settings.auditLogs.table.source')}</TableHead>
<TableHead>{t('settings.auditLogs.table.action')}</TableHead>
<TableHead>{t('settings.auditLogs.table.entity')}</TableHead>
<TableHead>{t('settings.auditLogs.table.details')}</TableHead>
</TableRow>
</TableHeader>
<TableBody>
@@ -82,7 +82,7 @@ export function AuditLogsTable() {
{(!logs || logs.length === 0) && (
<TableRow>
<TableCell colSpan={5} className="text-center py-8 text-muted-foreground">
No logs found.
{t('settings.auditLogs.table.empty')}
</TableCell>
</TableRow>
)}
@@ -48,7 +48,7 @@ export function McpSettingsCard() {
const copyToClipboard = (text: string) => {
navigator.clipboard.writeText(text);
toast({ title: "Copied!" });
toast({ title: t('settings.mcp.copied', "Copied!") });
}
const { data: settings, isLoading } = useQuery<any>({
@@ -97,19 +97,19 @@ export function McpSettingsCard() {
<CardHeader>
<div className="flex items-center gap-2">
<Server className="h-5 w-5 text-primary" />
<CardTitle>MCP Server Configuration</CardTitle>
<CardTitle>{t('settings.mcp.title')}</CardTitle>
</div>
<CardDescription>
Configure the Model Context Protocol (MCP) server settings.
The MCP server runs on the same port as the application (/api/mcp).
{t('settings.mcp.description')}
<span className="block mt-1 text-xs">{t('settings.mcp.descriptionDetail', "The MCP server runs on the same port as the application (/api/mcp).")}</span>
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div className="flex items-center justify-between">
<Label htmlFor="mcp_enabled" className="flex flex-col gap-1">
<span>Enable MCP Server</span>
<span>{t('settings.mcp.enableLabel')}</span>
<span className="font-normal text-xs text-muted-foreground">
Allow external AI tools to connect via MCP protocol.
{t('settings.mcp.enableDesc')}
</span>
</Label>
<Switch
@@ -169,7 +169,7 @@ export function McpSettingsCard() {
</div>
<div className="grid gap-2">
<Label htmlFor="mcp_port">Port (Informational)</Label>
<Label htmlFor="mcp_port">{t('settings.mcp.portLabel')}</Label>
<Input
id="mcp_port"
value={formData.mcp_port}
@@ -179,7 +179,7 @@ export function McpSettingsCard() {
className="bg-muted"
/>
<p className="text-xs text-muted-foreground">
Currently runs on the main application port. Separate port configuration coming soon.
{t('settings.mcp.portDesc')}
</p>
</div>
@@ -0,0 +1,116 @@
import { useState } from "react";
import { useTranslation } from "react-i18next";
import { Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter } from "@/components/ui/card";
import { Label } from "@/components/ui/label";
import { Checkbox } from "@/components/ui/checkbox";
import { Button } from "@/components/ui/button";
import { Download, Loader2, FileJson } from "lucide-react";
import { apiRequest } from "@/lib/queryClient";
import { useToast } from "@/hooks/use-toast";
import { User } from "@shared/schema";
interface DataExportCardProps {
user: User | undefined | null;
}
export function DataExportCard({ user }: DataExportCardProps) {
const { t } = useTranslation();
const { toast } = useToast();
const [includeTasks, setIncludeTasks] = useState(true);
const [includeLabels, setIncludeLabels] = useState(true);
const [includeSettings, setIncludeSettings] = useState(false);
const [isExporting, setIsExporting] = useState(false);
const handleExport = async () => {
try {
setIsExporting(true);
const response = await apiRequest("POST", "/api/user/export", {
includeTasks,
includeLabels,
includeSettings
});
if (!response.ok) throw new Error("Export failed");
// Handle blob download
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `taskflow_export_${user?.username}_${new Date().toISOString().split('T')[0]}.json`;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
toast({ title: t('settings.export.success', "Data exported successfully") });
} catch (error) {
console.error(error);
toast({
title: t('settings.export.error', "Failed to export data"),
variant: "destructive"
});
} finally {
setIsExporting(false);
}
};
return (
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<FileJson className="w-5 h-5" />
{t('settings.export.title')}
</CardTitle>
<CardDescription>
{t('settings.export.description')}
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div className="flex items-center space-x-2">
<Checkbox
id="tasks"
checked={includeTasks}
onCheckedChange={(c) => setIncludeTasks(!!c)}
/>
<Label htmlFor="tasks">{t('settings.export.tasks')}</Label>
</div>
<div className="flex items-center space-x-2">
<Checkbox
id="labels"
checked={includeLabels}
onCheckedChange={(c) => setIncludeLabels(!!c)}
/>
<Label htmlFor="labels">{t('settings.export.labels')}</Label>
</div>
{user?.role === 'admin' && (
<div className="flex items-center space-x-2">
<Checkbox
id="settings"
checked={includeSettings}
onCheckedChange={(c) => setIncludeSettings(!!c)}
/>
<Label htmlFor="settings">
{t('settings.export.systemSettings')}
</Label>
</div>
)}
</CardContent>
<CardFooter>
<Button
onClick={handleExport}
disabled={isExporting || (!includeTasks && !includeLabels && !includeSettings)}
>
{isExporting ? <Loader2 className="mr-2 h-4 w-4 animate-spin" /> : <Download className="mr-2 h-4 w-4" />}
{t('settings.export.button')}
</Button>
</CardFooter>
</Card>
);
}
+95 -28
View File
@@ -93,7 +93,22 @@
"minutesPlaceholder": "Minuten (optional)",
"duration": "Dauer",
"durationNone": "Keine",
"startDate": "Startdatum"
"startDate": "Startdatum",
"recurrence": {
"label": "Wiederholen:",
"none": "Nie",
"daily": "Täglich",
"weekly": "Wöchentlich",
"monthly": "Monatlich",
"yearly": "Jährlich",
"every": "Alle",
"units": {
"daily": "Tage",
"weekly": "Wochen",
"monthly": "Monate",
"yearly": "Jahre"
}
}
},
"taskDetails": {
"title": "Aufgabendetails",
@@ -211,6 +226,28 @@
},
"settings": {
"title": "Einstellungen",
"export": {
"title": "Datenexport",
"description": "Laden Sie Ihre Daten als JSON-Datei herunter.",
"tasks": "Aufgaben",
"labels": "Labels",
"systemSettings": "Systemeinstellungen (Admin)",
"button": "Daten exportieren",
"success": "Daten erfolgreich exportiert",
"error": "Fehler beim Exportieren der Daten"
},
"auditLogs": {
"title": "Audit-Protokolle",
"description": "Verfolgen Sie alle Systemänderungen und KI-Aktionen.",
"table": {
"time": "Zeit",
"source": "Quelle",
"action": "Aktion",
"entity": "Entität",
"details": "Details",
"empty": "Keine Protokolle gefunden."
}
},
"language": {
"title": "Sprache",
"description": "Wähle deine bevorzugte Sprache",
@@ -237,7 +274,13 @@
"description": "Systemweite Einstellungen und Benutzerverwaltung",
"manageUsers": "Benutzer & Registrierung verwalten",
"smtpSettings": "SMTP Einstellungen",
"systemSettings": "Systemeinstellungen (KI/SMTP)"
"systemSettings": "Systemeinstellungen (KI/SMTP)",
"tabs": {
"general": "Allgemein",
"ai": "KI-System",
"mcp": "MCP-Integration",
"audit": "Audit-Logs"
}
},
"smtp": {
"title": "E-Mail Einstellungen (SMTP)",
@@ -281,40 +324,64 @@
"copy": "In die Zwischenablage kopieren",
"instructions": "Konfigurieren Sie Ihren MCP-Client (z. B. Claude Desktop) mit dieser URL und diesem Token."
},
"mcp": {
"title": "MCP Server Konfiguration",
"description": "Konfigurieren Sie die Model Context Protocol (MCP) Server-Einstellungen.",
"descriptionDetail": "Der MCP-Server läuft auf demselben Port wie die Anwendung (/api/mcp).",
"enableLabel": "MCP-Server aktivieren",
"enableDesc": "Erlauben Sie externen KI-Tools über das MCP-Protokoll eine Verbindung.",
"portLabel": "Port (Info)",
"portDesc": "Läuft derzeit auf dem Hauptanwendungsport. Separate Konfiguration folgt.",
"status": "Server Status",
"running": "Aktiv",
"url": "Endpunkt-URL (SSE)",
"apiKey": "Zugriffstoken",
"generate": "Token generieren",
"revoke": "Token widerrufen",
"generated": "Zugriffstoken generiert",
"revoked": "Zugriffstoken widerrufen",
"noKey": "Kein aktives Token. Generieren Sie eines, um sich zu verbinden.",
"copy": "In Zwischenablage kopieren",
"copied": "Kopiert!",
"instructions": "Konfigurieren Sie Ihren MCP-Client (z. B. Claude Desktop) mit dieser URL und diesem Token."
},
"ai": {
"title": "KI-Konfiguration",
"description": "Konfigurieren Sie den globalen KI-Anbieter für den Assistenten.",
"provider": "KI-Anbieter",
"apiKey": "API-Schlüssel",
"model": "Modellname",
"baseUrl": "Basis-URL (Optional, z. B. für Ollama)",
"enableUser": "KI-Assistent aktivieren",
"enableUserDesc": "Zeige das KI-Chat-Widget an."
"baseUrl": "Basis-URL",
"systemPrompt": "System-Prompt",
"systemPromptPlaceholder": "Definieren Sie die Persona und Regeln der KI...",
"save": "KI-Einstellungen speichern",
"saved": "Einstellungen gespeichert",
"error": "Fehler beim Speichern",
"ollama": {
"placeholder": "Optional für Ollama",
"pull": "Modell laden",
"pullPlaceholder": "z.B. llama3",
"fetch": "Modelle abrufen",
"found": "{{count}} Modelle gefunden",
"pullSuccess": "Modell erfolgreich geladen",
"pullError": "Fehler beim Laden des Modells",
"connectError": "Verbindung zu Ollama fehlgeschlagen"
}
}
},
"ai": {
"title": "KI-Assistent",
"assistant": "KI Assistent",
"welcome": "Wie kann ich Ihnen heute bei Ihren Aufgaben helfen?",
"welcomeTitle": "Wie kann ich Ihnen helfen?",
"welcomeDesc": "Ich kann Sie bei Ihren Aufgaben, Ihrer Planung und mehr unterstützen.",
"thinking": "Denke nach...",
"placeholder": "Stellen Sie eine Frage...",
"newChat": "Neuer Chat",
"newChatDefault": "Neuer Chat",
"startChat": "Neuen Chat starten",
"selectConversation": "Chat wechseln",
"recentChats": "Letzte Chats",
"noChats": "Keine letzten Chats",
"chatRenamed": "Chat umbenannt",
"chatDeleted": "Chat gelöscht",
"deleteConfirm": "Diesen Chat wirklich löschen?",
"noConversation": "Kein Chat ausgewählt",
"sendFailed": "Senden fehlgeschlagen",
"errorSending": "Fehler beim Senden",
"disclaimer": "KI kann Fehler machen. Überprüfen Sie wichtige Informationen.",
"error": "Ich bin auf einen Fehler gestoßen"
},
"newChatDefault": "Neuer Chat",
"startChat": "Neuen Chat starten",
"selectConversation": "Chat wechseln",
"recentChats": "Letzte Chats",
"noChats": "Keine letzten Chats",
"chatRenamed": "Chat umbenannt",
"chatDeleted": "Chat gelöscht",
"deleteConfirm": "Diesen Chat wirklich löschen?",
"noConversation": "Kein Chat ausgewählt",
"sendFailed": "Senden fehlgeschlagen",
"errorSending": "Fehler beim Senden",
"disclaimer": "KI kann Fehler machen. Überprüfen Sie wichtige Informationen.",
"error": "Ich bin auf einen Fehler gestoßen",
"userManagement": {
"title": "Benutzerverwaltung",
"registration": "Registrierung",
+82 -7
View File
@@ -93,7 +93,22 @@
"minutesPlaceholder": "Minutes (optional)",
"duration": "Duration",
"durationNone": "None",
"startDate": "Start Date"
"startDate": "Start Date",
"recurrence": {
"label": "Repeat:",
"none": "None",
"daily": "Daily",
"weekly": "Weekly",
"monthly": "Monthly",
"yearly": "Yearly",
"every": "Every",
"units": {
"daily": "days",
"weekly": "weeks",
"monthly": "months",
"yearly": "years"
}
}
},
"taskDetails": {
"title": "Task Details",
@@ -211,6 +226,28 @@
},
"settings": {
"title": "Settings",
"export": {
"title": "Data Export",
"description": "Download your data as a JSON file.",
"tasks": "Tasks",
"labels": "Labels",
"systemSettings": "System Settings (Admin)",
"button": "Export Data",
"success": "Data exported successfully",
"error": "Failed to export data"
},
"auditLogs": {
"title": "Audit Logs",
"description": "Track all system changes and AI actions.",
"table": {
"time": "Time",
"source": "Source",
"action": "Action",
"entity": "Entity",
"details": "Details",
"empty": "No logs found."
}
},
"language": {
"title": "Language",
"description": "Choose your preferred language",
@@ -237,7 +274,13 @@
"description": "System administration and configuration",
"manageUsers": "Manage Users",
"smtpSettings": "SMTP / Email Settings",
"systemSettings": "System Settings (AI/SMTP)"
"systemSettings": "System Settings (AI/SMTP)",
"tabs": {
"general": "General",
"ai": "AI System",
"mcp": "MCP Integration",
"audit": "Audit Logs"
}
},
"smtp": {
"title": "Email Settings (SMTP)",
@@ -280,8 +323,13 @@
"manageTemplates": "Manage Templates"
},
"mcp": {
"title": "MCP Server Integration",
"description": "Connect AI assistants to TaskFlow via Model Context Protocol.",
"title": "MCP Server Configuration",
"description": "Configure the Model Context Protocol (MCP) server settings.",
"descriptionDetail": "The MCP server runs on the same port as the application (/api/mcp).",
"enableLabel": "Enable MCP Server",
"enableDesc": "Allow external AI tools to connect via MCP protocol.",
"portLabel": "Port (Informational)",
"portDesc": "Currently runs on the main application port. Separate port configuration coming soon.",
"status": "Server Status",
"running": "Active",
"url": "Endpoint URL (SSE)",
@@ -292,6 +340,7 @@
"revoked": "Access Token revoked",
"noKey": "No token active. Generate one to connect.",
"copy": "Copy to Clipboard",
"copied": "Copied!",
"instructions": "Configure your MCP client (e.g. Claude Desktop) with this URL and Token."
},
"ai": {
@@ -300,11 +349,37 @@
"provider": "AI Provider",
"apiKey": "API Key",
"model": "Model Name",
"baseUrl": "Base URL (Optional, e.g. for Ollama)",
"enableUser": "Enable AI Assistant",
"enableUserDesc": "Show the AI chat widget."
"baseUrl": "Base URL",
"systemPrompt": "System Prompt",
"systemPromptPlaceholder": "Define the AI's persona and rules...",
"save": "Save AI Settings",
"saved": "Settings saved",
"error": "Failed to save settings",
"ollama": {
"placeholder": "Optional for Ollama",
"pull": "Pull Model",
"pullPlaceholder": "e.g. llama3",
"fetch": "Fetch Models",
"found": "Found {{count}} models",
"pullSuccess": "Model pulled successfully",
"pullError": "Failed to pull model",
"connectError": "Could not connect to Ollama"
}
}
},
"smtp": {
"title": "Email Settings (SMTP)",
"description": "Configure outgoing email server",
"host": "Host",
"port": "Port",
"user": "User",
"password": "Password",
"from": "From Address",
"secure": "Secure (TLS)",
"save": "Save Email Settings",
"saving": "Saving...",
"saveSuccess": "Settings saved successfully"
},
"ai": {
"title": "AI Assistant",
"welcome": "How can I help you manage your tasks today?",
+12 -5
View File
@@ -3,7 +3,7 @@ import { SMTPSettingsCard } from "@/components/admin/SMTPSettingsCard";
import { AiSettingsCard } from "@/components/admin/AiSettingsCard";
import { useTranslation } from "react-i18next";
import { Button } from "@/components/ui/button";
import { ArrowLeft, Shield, Bot, FileText, Settings } from "lucide-react";
import { ArrowLeft, Shield, Bot, FileText, Settings, Sparkles } from "lucide-react";
import { useLocation } from "wouter";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { AuditLogsTable } from "@/components/admin/AuditLogsTable";
@@ -35,23 +35,30 @@ export default function AdminSettings() {
<TabsList>
<TabsTrigger value="settings" className="flex items-center gap-2">
<Settings className="h-4 w-4" />
General & AI
{t('settings.admin.tabs.general')}
</TabsTrigger>
<TabsTrigger value="ai" className="flex items-center gap-2">
<Sparkles className="h-4 w-4" />
{t('settings.admin.tabs.ai')}
</TabsTrigger>
<TabsTrigger value="mcp" className="flex items-center gap-2">
<Bot className="h-4 w-4" />
MCP Integration
{t('settings.admin.tabs.mcp')}
</TabsTrigger>
<TabsTrigger value="audit" className="flex items-center gap-2">
<FileText className="h-4 w-4" />
Audit Logs
{t('settings.admin.tabs.audit')}
</TabsTrigger>
</TabsList>
<TabsContent value="settings" className="space-y-6">
<AiSettingsCard />
<SMTPSettingsCard />
</TabsContent>
<TabsContent value="ai">
<AiSettingsCard />
</TabsContent>
<TabsContent value="mcp">
<McpSettingsCard />
</TabsContent>
+214 -164
View File
@@ -3,6 +3,7 @@ import { useTranslation } from "react-i18next";
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Textarea } from "@/components/ui/textarea";
import { ScrollArea } from "@/components/ui/scroll-area";
import {
DropdownMenu,
@@ -22,7 +23,24 @@ import {
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog";
import { Plus, MessageSquare, Trash2, Send, Bot, User as UserIcon, Loader2, Sparkles, AlertCircle, Pencil, Check, ChevronDown, History, X } from "lucide-react";
import {
Send,
Bot,
User as UserIcon,
Sparkles,
Trash2,
MessageSquare,
Pencil,
X,
ChevronDown,
Plus,
Calendar,
CheckCircle2,
Clock,
AlertCircle,
Download,
Loader2
} from "lucide-react";
import { apiRequest } from "@/lib/queryClient";
import { cn } from "@/lib/utils";
import { formatDistanceToNow } from "date-fns";
@@ -99,9 +117,15 @@ export default function AiChatPage() {
const [editingMessageId, setEditingMessageId] = useState<string | null>(null);
const [editMessageContent, setEditMessageContent] = useState("");
// Check AI Configuration Status
const { data: aiStatus, isLoading: isLoadingStatus } = useQuery<{ configured: boolean }>({
queryKey: ['/api/ai/status'],
});
// Fetch Conversations
const { data: conversations, isLoading: isLoadingConvs } = useQuery<Conversation[]>({
queryKey: ["/api/ai/conversations"],
enabled: aiStatus?.configured
});
// Select latest conversation on load if none selected
@@ -111,10 +135,15 @@ export default function AiChatPage() {
}
}, [conversations, selectedConversationId]);
// Fetch Messages for selected conversation (disabled if 'new')
// Fetch Messages for selected conversation
const { data: messages, isLoading: isLoadingMessages } = useQuery<Message[]>({
queryKey: ["/api/ai/conversations", selectedConversationId, "messages"],
enabled: !!selectedConversationId && selectedConversationId !== 'new',
refetchInterval: (query) => {
// Poll if the last message is from the user (waiting for AI response)
const lastMsg = query.state.data?.slice(-1)[0];
return lastMsg?.role === 'user' ? 2000 : false;
}
});
const scrollToBottom = () => {
@@ -136,55 +165,26 @@ export default function AiChatPage() {
},
onSuccess: (newConv) => {
queryClient.invalidateQueries({ queryKey: ["/api/ai/conversations"] });
// Do NOT set selected ID here, handled in handleSend to avoid race conditions or double sets
},
});
const deleteConversationMutation = useMutation({
mutationFn: async (id: string) => {
await apiRequest("DELETE", `/api/ai/conversations/${id}`);
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["/api/ai/conversations"] });
if (selectedConversationId !== 'new') {
setSelectedConversationId(null);
}
toast({ title: t('ai.chatDeleted', 'Chat deleted') });
},
});
const renameConversationMutation = useMutation({
mutationFn: async ({ id, title }: { id: string; title: string }) => {
await apiRequest("PATCH", `/api/ai/conversations/${id}`, { title });
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["/api/ai/conversations"] });
setEditingId(null);
toast({ title: t('ai.chatRenamed', 'Chat renamed') });
},
});
const generateTitleMutation = useMutation({
mutationFn: async ({ messages }: { conversationId: string, messages: any[] }) => {
const res = await apiRequest("POST", "/api/ai/generate-title", { messages });
if (!res.ok) throw new Error("Failed to generate title");
return res.json();
},
onSuccess: (data, vars) => {
renameConversationMutation.mutate({ id: vars.conversationId, title: data.title });
}
});
// ... (Delete/Rename skipped for brevity in prompt, keeping existing) ...
const sendMessageMutation = useMutation({
mutationFn: async ({ conversationId, content }: { conversationId: string, content: string }) => {
// ALWAYS use the main chat endpoint which is now async-friendly
const res = await apiRequest("POST", "/api/ai/chat", {
conversationId,
content,
clientTime: new Date().toLocaleString()
});
if (!res.ok) {
const errData = await res.json();
throw new Error(errData.error || t('ai.sendFailed', 'Failed to send message'));
try {
const errData = await res.json();
throw new Error(errData.error || t('ai.sendFailed', 'Failed to send message'));
} catch (e) {
throw new Error(t('ai.sendFailed', 'Failed to send message'));
}
}
return res.json();
},
@@ -192,6 +192,7 @@ export default function AiChatPage() {
await queryClient.cancelQueries({ queryKey: ["/api/ai/conversations", conversationId, "messages"] });
const previousMessages = queryClient.getQueryData<Message[]>(["/api/ai/conversations", conversationId, "messages"]);
// Optimistic update
queryClient.setQueryData(["/api/ai/conversations", conversationId, "messages"], (old: Message[] = []) => [
...old,
{ id: 'temp-' + Date.now(), role: 'user', content: content, createdAt: new Date().toISOString() }
@@ -214,21 +215,17 @@ export default function AiChatPage() {
variant: "destructive"
});
},
onSuccess: (botMessage, vars, context) => {
onSuccess: (userMessage, vars, context) => { // Returns USER message now
queryClient.invalidateQueries({ queryKey: ["/api/ai/conversations", vars.conversationId, "messages"] });
queryClient.invalidateQueries({ queryKey: ["/api/ai/conversations"] });
queryClient.invalidateQueries({ queryKey: ["/api/tasks"] });
queryClient.invalidateQueries({ queryKey: ["/api/goals"] });
setLatestMessageId(botMessage.id);
// Auto-title if this was the first exchange (previous messages empty or undefined)
if (!context?.previousMessages || context.previousMessages.length === 0) {
const messagesForTitle = [
{ role: 'user', content: vars.content },
{ role: 'assistant', content: botMessage.content }
];
generateTitleMutation.mutate({ conversationId: vars.conversationId, messages: messagesForTitle });
}
// Note: We don't get the bot message here anymore immediately.
// The polling (refetchInterval) will pick it up when ready.
// Auto-title if this was the first exchange?
// We can still do it, but we won't have the bot response content yet for the title gen.
// Maybe title gen should happen on backend in the background too?
// For now, let's skip auto-title on first msg OR move it to backend trigger.
},
});
@@ -335,7 +332,7 @@ export default function AiChatPage() {
editMessageMutation.mutate({ id: editingMessageId, content: editMessageContent });
};
const handleInputKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
const handleInputKeyDown = (e: React.KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => {
if (e.key === 'ArrowUp' && !input && !editingMessageId && messages) {
e.preventDefault();
// Find last user message
@@ -356,6 +353,7 @@ export default function AiChatPage() {
{/* Header / Top Navigation Bar */}
<div className="h-16 border-b flex items-center px-4 md:px-6 justify-between shrink-0 bg-background/80 backdrop-blur-sm z-30 sticky top-0 shadow-sm">
{/* Left: Branding, History & Current Title */}
{/* Left: Branding, History & Current Title */}
<div className="flex items-center gap-3 flex-1 min-w-0">
<div className="w-8 h-8 rounded-full bg-primary/10 flex items-center justify-center shrink-0">
@@ -363,120 +361,164 @@ export default function AiChatPage() {
</div>
{/* Logic: If editing current title, show input. Else show Dropdown. */}
{editingId === selectedConversationId ? (
<div className="flex items-center gap-2 flex-1 max-w-[300px]">
<Input
value={editName}
onChange={(e) => setEditName(e.target.value)}
onKeyDown={handleKeyDown}
onBlur={saveName}
autoFocus
className="h-9"
/>
<Button size="icon" variant="ghost" onClick={() => setEditingId(null)}>
<X className="w-4 h-4" />
</Button>
</div>
) : (
<div className="flex items-center gap-2 min-w-0">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" className="h-auto py-2 px-3 font-semibold text-lg flex gap-2 items-center hover:bg-muted/50 transition-colors rounded-lg max-w-full">
<div className="flex flex-col items-start leading-none min-w-0">
<span className="bg-gradient-to-r from-violet-600 to-indigo-600 bg-clip-text text-transparent text-lg truncate max-w-[200px] md:max-w-[400px]">
{currentTitle}
</span>
<span className="text-[10px] text-muted-foreground font-normal flex items-center gap-1">
{t('ai.selectConversation', 'Switch Chat')} <ChevronDown className="w-3 h-3" />
</span>
</div>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="start" className="w-[300px] max-h-[500px] overflow-y-auto">
<DropdownMenuLabel>{t('ai.recentChats', 'Recent Chats')}</DropdownMenuLabel>
<DropdownMenuSeparator />
{conversations?.map(conv => (
<DropdownMenuItem
key={conv.id}
onClick={() => setSelectedConversationId(conv.id)}
className={cn("flex justify-between items-center cursor-pointer py-3 group", selectedConversationId === conv.id ? "bg-muted" : "")}
>
{editingId === conv.id ? (
<div className="flex items-center gap-2 flex-1 onClick-stop">
<Input
value={editName}
onChange={(e) => setEditName(e.target.value)}
onKeyDown={handleKeyDown}
onClick={(e) => e.stopPropagation()}
onBlur={saveName}
autoFocus
className="h-8 text-xs"
/>
</div>
) : (
<>
<div className="flex items-center gap-2 overflow-hidden flex-1">
<MessageSquare className="w-4 h-4 text-muted-foreground shrink-0" />
<span className="truncate font-medium">{conv.title}</span>
</div>
<div className="flex items-center opacity-0 group-hover:opacity-100 transition-opacity">
<Button
variant="ghost"
size="icon"
className="h-6 w-6 text-muted-foreground"
onClick={(e) => startEditing(conv, e)}
>
<Pencil className="w-3 h-3" />
</Button>
<Button
variant="ghost"
size="icon"
className="h-6 w-6 text-muted-foreground hover:text-destructive"
onClick={(e) => handleDelete(conv.id, e)}
>
<Trash2 className="w-3 h-3" />
</Button>
</div>
</>
)}
</DropdownMenuItem>
))}
{(!conversations || conversations.length === 0) && (
<div className="p-4 text-center text-sm text-muted-foreground">
{t('ai.noChats', 'No recent chats')}
</div>
)}
</DropdownMenuContent>
</DropdownMenu>
{/* Edit Button: Only show if we have a REAL selected conversation (not 'new') */}
{selectedConversationId && selectedConversationId !== 'new' && (
<Button
variant="ghost"
size="icon"
className="h-8 w-8 text-muted-foreground hover:bg-muted"
onClick={(e) => {
const conv = conversations?.find(c => c.id === selectedConversationId);
if (conv) startEditing(conv, e);
}}
>
<Pencil className="w-4 h-4" />
{aiStatus?.configured && (
editingId === selectedConversationId ? (
<div className="flex items-center gap-2 flex-1 max-w-[300px]">
<Input
value={editName}
onChange={(e) => setEditName(e.target.value)}
onKeyDown={handleKeyDown}
onBlur={saveName}
autoFocus
className="h-9"
/>
<Button size="icon" variant="ghost" onClick={() => setEditingId(null)}>
<X className="w-4 h-4" />
</Button>
)}
</div>
</div>
) : (
<div className="flex items-center gap-2 min-w-0">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" className="h-auto py-2 px-3 font-semibold text-lg flex gap-2 items-center hover:bg-muted/50 transition-colors rounded-lg max-w-full">
<div className="flex flex-col items-start leading-none min-w-0">
<span className="bg-gradient-to-r from-violet-600 to-indigo-600 bg-clip-text text-transparent text-lg truncate max-w-[200px] md:max-w-[400px]">
{currentTitle}
</span>
<span className="text-[10px] text-muted-foreground font-normal flex items-center gap-1">
{t('ai.selectConversation', 'Switch Chat')} <ChevronDown className="w-3 h-3" />
</span>
</div>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="start" className="w-[300px] max-h-[500px] overflow-y-auto">
<DropdownMenuLabel>{t('ai.recentChats', 'Recent Chats')}</DropdownMenuLabel>
<DropdownMenuSeparator />
{conversations?.map(conv => (
<DropdownMenuItem
key={conv.id}
onClick={() => setSelectedConversationId(conv.id)}
className={cn("flex justify-between items-center cursor-pointer py-3 group", selectedConversationId === conv.id ? "bg-muted" : "")}
>
{editingId === conv.id ? (
<div className="flex items-center gap-2 flex-1 onClick-stop">
<Input
value={editName}
onChange={(e) => setEditName(e.target.value)}
onKeyDown={handleKeyDown}
onClick={(e) => e.stopPropagation()}
onBlur={saveName}
autoFocus
className="h-8 text-xs"
/>
</div>
) : (
<>
<div className="flex items-center gap-2 overflow-hidden flex-1">
<MessageSquare className="w-4 h-4 text-muted-foreground shrink-0" />
<span className="truncate font-medium">{conv.title}</span>
</div>
<div className="flex items-center opacity-0 group-hover:opacity-100 transition-opacity">
<Button
variant="ghost"
size="icon"
className="h-6 w-6 text-muted-foreground"
onClick={(e) => startEditing(conv, e)}
>
<Pencil className="w-3 h-3" />
</Button>
<Button
variant="ghost"
size="icon"
className="h-6 w-6 text-muted-foreground hover:text-destructive"
onClick={(e) => handleDelete(conv.id, e)}
>
<Trash2 className="w-3 h-3" />
</Button>
</div>
</>
)}
</DropdownMenuItem>
))}
{(!conversations || conversations.length === 0) && (
<div className="p-4 text-center text-sm text-muted-foreground">
{t('ai.noChats', 'No recent chats')}
</div>
)}
</DropdownMenuContent>
</DropdownMenu>
{/* Edit Button: Only show if we have a REAL selected conversation (not 'new') */}
{selectedConversationId && selectedConversationId !== 'new' && (
<Button
variant="ghost"
size="icon"
className="h-8 w-8 text-muted-foreground hover:bg-muted"
onClick={(e) => {
const conv = conversations?.find(c => c.id === selectedConversationId);
if (conv) startEditing(conv, e);
}}
>
<Pencil className="w-4 h-4" />
</Button>
)}
</div>
)
)}
</div>
{/* Right: New Chat Action */}
<Button onClick={handleCreateNew} size="sm" className="gap-2 shadow-sm rounded-full shrink-0">
<Plus className="w-4 h-4" />
<span className="hidden sm:inline">{t('ai.newChat', 'New Chat')}</span>
</Button>
{/* Right: Actions */}
<div className="flex items-center gap-2">
{aiStatus?.configured && (
<>
{/* Export Button */}
<Button
variant="ghost"
size="icon"
className="h-8 w-8 text-muted-foreground hover:bg-muted"
onClick={() => {
if (!conversations || conversations.length === 0) return;
const dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify({
exportDate: new Date().toISOString(),
conversations: conversations,
activeMessages: messages
}, null, 2));
const downloadAnchorNode = document.createElement('a');
downloadAnchorNode.setAttribute("href", dataStr);
downloadAnchorNode.setAttribute("download", `ai_chat_export_${new Date().toISOString()}.json`);
document.body.appendChild(downloadAnchorNode);
downloadAnchorNode.click();
downloadAnchorNode.remove();
}}
title={t('ai.export', 'Export Chat')}
>
<Download className="w-4 h-4" />
</Button>
<Button onClick={handleCreateNew} size="sm" className="gap-2 shadow-sm rounded-full shrink-0">
<Plus className="w-4 h-4" />
<span className="hidden sm:inline">{t('ai.newChat', 'New Chat')}</span>
</Button>
</>
)}
</div>
</div>
{/* Main Chat Area */}
<div className="flex-1 flex flex-col min-w-0 relative overflow-hidden">
{!selectedConversationId ? (
{!aiStatus?.configured ? (
<div className="flex-1 flex flex-col items-center justify-center text-muted-foreground p-8 text-center animate-in fade-in zoom-in duration-300">
<div className="w-24 h-24 bg-destructive/10 rounded-full flex items-center justify-center mb-6">
<Bot className="w-12 h-12 text-destructive" />
</div>
<h3 className="text-3xl font-bold mb-3 tracking-tight text-foreground">
{t('ai.notConfiguredTitle', 'AI Not Configured')}
</h3>
<p className="max-w-md mb-8 text-lg opacity-80 leading-relaxed">
{t('ai.notConfiguredDesc', 'Please configure an AI provider in the admin settings to start using the assistant.')}
</p>
</div>
) : !selectedConversationId ? (
<div className="flex-1 flex flex-col items-center justify-center text-muted-foreground p-8 text-center animate-in fade-in zoom-in duration-300">
<div className="w-24 h-24 bg-gradient-to-br from-violet-500/10 to-indigo-500/10 rounded-full flex items-center justify-center mb-6 animate-pulse">
<Sparkles className="w-12 h-12 text-violet-500" />
@@ -591,16 +633,24 @@ export default function AiChatPage() {
<div className="pt-2 px-4 md:px-6 md:pt-2 pb-6 bg-background/50 backdrop-blur-sm shrink-0">
<div className="max-w-3xl mx-auto space-y-3">
<form
className="relative flex items-center gap-2 bg-muted/40 border rounded-2xl px-4 py-2.5 shadow-sm focus-within:ring-2 focus-within:ring-primary/20 focus-within:border-primary transition-all hover:bg-muted/60"
className="relative flex items-start gap-2 bg-muted/40 border rounded-2xl px-4 py-1.5 shadow-sm focus-within:ring-2 focus-within:ring-primary/20 focus-within:border-primary transition-all hover:bg-muted/60"
onSubmit={handleSend}
>
<Sparkles className="w-5 h-5 text-muted-foreground/70" />
<Input
<Sparkles className="w-5 h-5 text-muted-foreground/70 self-start mt-2" />
<Textarea
value={input}
onChange={(e) => setInput(e.target.value)}
onKeyDown={handleInputKeyDown}
onKeyDown={(e) => {
// Handle Shift+Enter for newline
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
handleSend();
}
// Let Shift+Enter pass through
handleInputKeyDown(e);
}}
placeholder={t('ai.placeholder', 'Ask me anything about your tasks...')}
className="flex-1 border-0 bg-transparent shadow-none focus-visible:ring-0 px-3 h-11 text-base placeholder:text-muted-foreground/60"
className="flex-1 border-0 bg-transparent shadow-none focus-visible:ring-0 px-3 min-h-[44px] max-h-[200px] text-base placeholder:text-muted-foreground/60 resize-none py-2.5"
autoFocus
disabled={sendMessageMutation.isPending || createConversationMutation.isPending || editMessageMutation.isPending}
/>
@@ -609,7 +659,7 @@ export default function AiChatPage() {
disabled={!input.trim() || sendMessageMutation.isPending || createConversationMutation.isPending || editMessageMutation.isPending}
size="icon"
className={cn(
"h-9 w-9 rounded-xl shrink-0 transition-all duration-300",
"h-9 w-9 rounded-xl shrink-0 transition-all duration-300 self-end mb-1",
input.trim()
? "opacity-100 scale-100 bg-primary text-primary-foreground shadow-md hover:scale-105"
: "opacity-0 scale-75"
+168
View File
@@ -0,0 +1,168 @@
import { useRoute, useLocation } from "wouter";
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
import { Task, User } from "@shared/schema";
import { useTranslation } from "react-i18next";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Checkbox } from "@/components/ui/checkbox";
import { ScrollArea } from "@/components/ui/scroll-area";
import { Sun, Moon, ArrowRight, CheckCircle2, ListTodo, Calendar as CalendarIcon } from "lucide-react";
import { motion, AnimatePresence } from "framer-motion";
import { apiRequest } from "@/lib/queryClient";
import { useToast } from "@/hooks/use-toast";
import { format } from "date-fns";
import { useState } from "react";
export default function FocusRoutinePage() {
const [match, params] = useRoute("/focus/routine/:type");
const type = params?.type as 'morning' | 'evening';
const { t } = useTranslation();
const [, setLocation] = useLocation();
const { toast } = useToast();
const queryClient = useQueryClient();
const [step, setStep] = useState(0);
const { data: user } = useQuery<User>({ queryKey: ["/api/user"] });
const { data: tasks = [] } = useQuery<Task[]>({ queryKey: ["/api/tasks"] });
// Filter tasks
const today = new Date();
const todayTasks = tasks.filter(t => {
if (!t.dueDate) return false;
const d = new Date(t.dueDate);
return d.getDate() === today.getDate() && d.getMonth() === today.getMonth();
});
const completedToday = todayTasks.filter(t => t.status === 'done');
const pendingTasks = tasks.filter(t => t.status !== 'done');
// Handlers
const handleComplete = async () => {
if (type === 'morning') {
setLocation('/focus');
} else {
triggerConfetti(0.5, 0.5);
toast({ title: t('routine.dayComplete', "Day Complete! Great job.") });
setLocation('/achievements');
}
};
if (!match || !['morning', 'evening'].includes(type)) {
return <div className="p-8">Invalid routine type</div>;
}
// Animation variants
const pageVariants = {
initial: { opacity: 0, y: 20 },
in: { opacity: 1, y: 0 },
out: { opacity: 0, y: -20 }
};
return (
<div className={`min-h-screen w-full flex flex-col justify-center items-center p-4 transition-colors duration-1000 ${type === 'morning' ? 'bg-orange-50/50 dark:bg-orange-950/20' : 'bg-indigo-50/50 dark:bg-indigo-950/20'}`}>
<motion.div
initial="initial" animate="in" exit="out" variants={pageVariants}
className="w-full max-w-2xl"
>
<Card className="border-none shadow-2xl bg-background/80 backdrop-blur-sm">
<CardHeader className="text-center pb-2">
<div className="mx-auto mb-4 w-16 h-16 rounded-full flex items-center justify-center bg-primary/10">
{type === 'morning' ? <Sun className="w-8 h-8 text-orange-500" /> : <Moon className="w-8 h-8 text-indigo-500" />}
</div>
<CardTitle className="text-3xl font-bold">
{type === 'morning' ? t('routine.goodMorning', 'Good Morning') : t('routine.goodEvening', 'Good Evening')}, {user?.username}
</CardTitle>
<p className="text-muted-foreground mt-2">
{type === 'morning'
? t('routine.morningSubtitle', "Let's plan your day for success.")
: t('routine.eveningSubtitle', "Time to reflect and unwind.")}
</p>
</CardHeader>
<CardContent className="pt-6">
<AnimatePresence mode="wait">
{type === 'morning' ? (
<MorningRoutine tasks={pendingTasks} onComplete={handleComplete} />
) : (
<EveningRoutine completed={completedToday} pending={pendingTasks} onComplete={handleComplete} />
)}
</AnimatePresence>
</CardContent>
</Card>
</motion.div>
</div>
);
}
function MorningRoutine({ tasks, onComplete }: { tasks: Task[], onComplete: () => void }) {
const { t } = useTranslation();
return (
<motion.div className="space-y-6">
<div className="bg-muted/50 p-4 rounded-lg">
<h3 className="font-semibold mb-2 flex items-center gap-2">
<ListTodo className="w-4 h-4" />
{t('routine.tasksForToday', 'Tasks for Today')}
</h3>
<ScrollArea className="h-[300px] pr-4">
{tasks.length === 0 ? (
<div className="text-center text-muted-foreground py-8">
{t('routine.noTasks', 'No tasks scheduled yet. Add some!')}
</div>
) : (
<div className="space-y-2">
{tasks.map(task => (
<div key={task.id} className="flex items-center gap-3 p-3 bg-card border rounded-md">
<div className={`w-1 h-8 rounded-full ${getPriorityColor(task.priority)}`} />
<span className="flex-1 font-medium">{task.title}</span>
{task.estimatedDuration && <span className="text-xs text-muted-foreground">{task.estimatedDuration}m</span>}
</div>
))}
</div>
)}
</ScrollArea>
</div>
<div className="flex justify-end pt-4">
<Button size="lg" onClick={onComplete} className="w-full sm:w-auto">
{t('routine.startFocus', 'Start Focus Mode')} <ArrowRight className="ml-2 w-4 h-4" />
</Button>
</div>
</motion.div>
)
}
function EveningRoutine({ completed, pending, onComplete }: { completed: Task[], pending: Task[], onComplete: () => void }) {
const { t } = useTranslation();
return (
<motion.div className="space-y-6">
<div className="grid grid-cols-2 gap-4">
<div className="p-4 bg-green-50 dark:bg-green-950/20 rounded-lg border border-green-100 dark:border-green-900 text-center">
<div className="text-3xl font-bold text-green-600 mb-1">{completed.length}</div>
<div className="text-sm text-green-700 dark:text-green-400">{t('routine.completed', 'Completed')}</div>
</div>
<div className="p-4 bg-orange-50 dark:bg-orange-950/20 rounded-lg border border-orange-100 dark:border-orange-900 text-center">
<div className="text-3xl font-bold text-orange-600 mb-1">{pending.length}</div>
<div className="text-sm text-orange-700 dark:text-orange-400">{t('routine.open', 'Remaining')}</div>
</div>
</div>
<div className="flex justify-end pt-4">
<Button size="lg" onClick={onComplete} className="w-full sm:w-auto">
{t('routine.endDay', 'End Day')} <CheckCircle2 className="ml-2 w-4 h-4" />
</Button>
</div>
</motion.div>
)
}
function getPriorityColor(priority: string) {
if (priority === 'high') return 'bg-red-500';
if (priority === 'medium') return 'bg-yellow-500';
return 'bg-blue-500';
}
// Temporary import fix if confetti not available in module scope
import { triggerConfetti } from "@/lib/confetti";
+4
View File
@@ -18,6 +18,7 @@ import { queryClient, apiRequest } from '@/lib/queryClient';
import { useToast } from '@/hooks/use-toast';
import { useLocation } from "wouter";
import { useNotifications } from '@/hooks/use-notifications';
import { DataExportCard } from '@/components/user/DataExportCard';
const NotificationSettings = () => {
const { t } = useTranslation();
@@ -552,6 +553,9 @@ export default function Settings({ onNavigateToTemplates }: SettingsProps) {
</CardContent>
</Card>
{/* Data Export */}
<DataExportCard user={user} />
{/* Admin Section */}
{
user?.role === 'admin' && (