Spaces:
Running
Running
File size: 15,866 Bytes
c2ea5ed |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 |
import React, { useState } from "react";
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import { Card, CardContent } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
import { Badge } from "@/components/ui/badge";
import { Separator } from "@/components/ui/separator";
import { ScrollArea } from "@/components/ui/scroll-area";
import {
Settings,
Palette,
Monitor,
Sun,
Moon,
Smartphone,
Check,
GitBranch,
Layers,
Brain,
Zap,
Clock,
DollarSign,
} from "lucide-react";
import { useKGDisplayMode } from "@/context/KGDisplayModeContext";
import { useModelPreferences } from "@/hooks/useModelPreferences";
import { AVAILABLE_MODELS, ModelConfig } from "@/lib/models";
interface SettingsModalProps {
open: boolean;
onOpenChange: (open: boolean) => void;
}
type Theme = "light" | "dark" | "system";
export function SettingsModal({ open, onOpenChange }: SettingsModalProps) {
const [activeSection, setActiveSection] = useState<string>("appearance");
const [currentTheme, setCurrentTheme] = useState<Theme>("system");
const { mode: kgDisplayMode, setMode: setKGDisplayMode } = useKGDisplayMode();
const {
selectedModel,
currentModelConfig,
updateModelPreference,
isLoading,
} = useModelPreferences();
const handleThemeChange = (theme: Theme) => {
setCurrentTheme(theme);
// Apply theme to document
const root = document.documentElement;
if (theme === "dark") {
root.classList.add("dark");
} else if (theme === "light") {
root.classList.remove("dark");
} else {
// System theme - detect user preference
const prefersDark = window.matchMedia(
"(prefers-color-scheme: dark)"
).matches;
if (prefersDark) {
root.classList.add("dark");
} else {
root.classList.remove("dark");
}
}
// Save to localStorage
localStorage.setItem("theme", theme);
};
React.useEffect(() => {
// Load saved theme on mount
const savedTheme = localStorage.getItem("theme") as Theme;
if (savedTheme) {
setCurrentTheme(savedTheme);
handleThemeChange(savedTheme);
}
}, []);
const themeOptions = [
{
id: "light" as Theme,
name: "Light",
description: "Light mode for bright environments",
icon: Sun,
},
{
id: "dark" as Theme,
name: "Dark",
description: "Dark mode for low-light environments",
icon: Moon,
},
{
id: "system" as Theme,
name: "System",
description: "Follows your system preference",
icon: Monitor,
},
];
const sidebarSections = [
{
id: "appearance",
name: "Appearance",
icon: Palette,
},
{
id: "models",
name: "Models",
icon: Brain,
},
{
id: "general",
name: "General",
icon: Settings,
},
];
const getCostLevelColor = (costLevel: string) => {
switch (costLevel) {
case "low":
return "text-green-600";
case "medium":
return "text-yellow-600";
case "high":
return "text-red-600";
default:
return "text-gray-600";
}
};
const getSpeedIcon = (speed: string) => {
switch (speed) {
case "fast":
return Zap;
case "medium":
return Clock;
case "slow":
return Brain;
default:
return Clock;
}
};
const renderModelCard = (model: ModelConfig) => {
const SpeedIcon = getSpeedIcon(model.speed);
const isSelected = selectedModel === model.id;
return (
<Card
key={model.id}
className={`cursor-pointer transition-all duration-200 hover:shadow-md ${
isSelected
? "ring-2 ring-primary border-primary bg-primary/5"
: "border-border hover:border-primary/50"
}`}
onClick={() => updateModelPreference(model.id)}
>
<CardContent className="p-4">
<div className="flex items-center justify-between">
<div className="flex items-center gap-3">
<div className="p-2 rounded-lg bg-muted">
<Brain className="h-4 w-4" />
</div>
<div className="flex-1">
<div className="flex items-center gap-2">
<h4 className="font-medium">{model.name}</h4>
{model.recommended && (
<Badge variant="secondary" className="text-xs">
Recommended
</Badge>
)}
</div>
<p className="text-sm text-muted-foreground mt-1">
{model.description}
</p>
<div className="flex items-center gap-4 mt-2">
<div className="flex items-center gap-1">
<SpeedIcon className="h-3 w-3 text-muted-foreground" />
<span className="text-xs text-muted-foreground capitalize">
{model.speed}
</span>
</div>
<div className="flex items-center gap-1">
<DollarSign
className={`h-3 w-3 ${getCostLevelColor(
model.costLevel
)}`}
/>
<span
className={`text-xs capitalize ${getCostLevelColor(
model.costLevel
)}`}
>
{model.costLevel} cost
</span>
</div>
<span className="text-xs text-muted-foreground">
{model.contextWindow} context
</span>
</div>
</div>
</div>
{isSelected && (
<div className="p-1 rounded-full bg-primary">
<Check className="h-3 w-3 text-primary-foreground" />
</div>
)}
</div>
</CardContent>
</Card>
);
};
const renderModelsSection = () => (
<div className="space-y-6">
{isLoading ? (
<div className="flex items-center justify-center p-8">
<div className="w-6 h-6 border-2 border-primary border-t-transparent rounded-full animate-spin mr-3" />
Loading model preferences...
</div>
) : (
<>
{/* Current Model Indicator */}
{currentModelConfig && (
<div className="bg-primary/10 border border-primary/20 p-4 rounded-lg">
<div className="flex items-center gap-3 mb-2">
<div className="p-2 rounded-lg bg-primary/20">
<Check className="h-4 w-4 text-primary" />
</div>
<div>
<h4 className="font-medium text-primary">
Currently Selected
</h4>
<p className="text-sm text-muted-foreground">
Active for all new graph generations
</p>
</div>
</div>
<div className="ml-11">
<p className="font-medium">{currentModelConfig.name}</p>
<p className="text-sm text-muted-foreground">
{currentModelConfig.description}
</p>
</div>
</div>
)}
<div>
<h3 className="text-lg font-semibold mb-4">Standard Models</h3>
<div className="space-y-3">
{AVAILABLE_MODELS.standard.map(renderModelCard)}
</div>
</div>
<Separator />
<div>
<h3 className="text-lg font-semibold mb-4">Reasoning Models</h3>
<p className="text-sm text-muted-foreground mb-4">
Specialized models for complex analysis and multi-step reasoning
tasks.
</p>
<div className="space-y-3">
{AVAILABLE_MODELS.reasoning.map(renderModelCard)}
</div>
</div>
<Separator />
<div className="bg-muted/30 p-4 rounded-lg">
<div className="flex items-center gap-2 mb-2">
<Brain className="h-4 w-4 text-muted-foreground" />
<span className="text-sm font-medium">Model Selection</span>
</div>
<p className="text-xs text-muted-foreground">
Your selected model will be used for all knowledge graph
extractions. Changes apply to new generations only.
</p>
</div>
</>
)}
</div>
);
const renderAppearanceSection = () => (
<div className="space-y-6">
<div>
<h3 className="text-lg font-semibold mb-4">Theme Selection</h3>
<div className="grid grid-cols-1 gap-3">
{themeOptions.map((option) => (
<Card
key={option.id}
className={`cursor-pointer transition-all hover:shadow-md ${
currentTheme === option.id
? "ring-2 ring-primary bg-primary/5"
: "hover:bg-muted/50"
}`}
onClick={() => handleThemeChange(option.id)}
>
<CardContent className="p-4">
<div className="flex items-center justify-between">
<div className="flex items-center gap-3">
<div className="p-2 rounded-lg bg-muted">
<option.icon className="h-4 w-4" />
</div>
<div>
<h4 className="font-medium">{option.name}</h4>
<p className="text-sm text-muted-foreground">
{option.description}
</p>
</div>
</div>
{currentTheme === option.id && (
<div className="p-1 rounded-full bg-primary">
<Check className="h-3 w-3 text-primary-foreground" />
</div>
)}
</div>
</CardContent>
</Card>
))}
</div>
</div>
<Separator />
<div>
<h3 className="text-lg font-semibold mb-4">Color Customization</h3>
<div className="bg-muted/30 p-4 rounded-lg">
<div className="flex items-center gap-2 mb-2">
<Smartphone className="h-4 w-4 text-muted-foreground" />
<span className="text-sm font-medium">Coming Soon</span>
<Badge variant="secondary" className="text-xs">
Future Update
</Badge>
</div>
<p className="text-sm text-muted-foreground">
Custom color themes and accent colors will be available in a future
update.
</p>
</div>
</div>
</div>
);
const renderGeneralSection = () => (
<div className="space-y-6">
<div>
<h3 className="text-lg font-semibold mb-4">Knowledge Graph Display</h3>
<div className="grid grid-cols-1 gap-3">
{[
{
id: "multiple" as const,
name: "Multiple Knowledge Graphs",
description:
"Show all knowledge graphs for research and comparison",
icon: Layers,
},
{
id: "single" as const,
name: "Single Knowledge Graph",
description:
"Show only the most recent/best knowledge graph per trace",
icon: GitBranch,
},
].map((option) => (
<Card
key={option.id}
className={`cursor-pointer transition-all hover:shadow-md ${
kgDisplayMode === option.id
? "ring-2 ring-primary bg-primary/5"
: "hover:bg-muted/50"
}`}
onClick={() => setKGDisplayMode(option.id)}
>
<CardContent className="p-4">
<div className="flex items-center justify-between">
<div className="flex items-center gap-3">
<div className="p-2 rounded-lg bg-muted">
<option.icon className="h-4 w-4" />
</div>
<div>
<h4 className="font-medium">{option.name}</h4>
<p className="text-sm text-muted-foreground">
{option.description}
</p>
</div>
</div>
{kgDisplayMode === option.id && (
<div className="p-1 rounded-full bg-primary">
<Check className="h-3 w-3 text-primary-foreground" />
</div>
)}
</div>
</CardContent>
</Card>
))}
</div>
</div>
<Separator />
<div>
<h3 className="text-lg font-semibold mb-4">Additional Settings</h3>
<div className="bg-muted/30 p-4 rounded-lg">
<div className="flex items-center gap-2 mb-2">
<Settings className="h-4 w-4 text-muted-foreground" />
<span className="text-sm font-medium">More Options</span>
<Badge variant="secondary" className="text-xs">
Coming Soon
</Badge>
</div>
<p className="text-sm text-muted-foreground">
More configuration options including language preferences, default
views, and notification settings will be available soon.
</p>
</div>
</div>
</div>
);
const renderSection = () => {
switch (activeSection) {
case "appearance":
return renderAppearanceSection();
case "models":
return renderModelsSection();
case "general":
return renderGeneralSection();
default:
return renderAppearanceSection();
}
};
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="max-w-4xl max-h-[90vh] p-0">
<DialogHeader className="p-6 pb-0">
<DialogTitle className="text-2xl font-bold flex items-center gap-2">
<Settings className="h-6 w-6" />
Settings & Preferences
</DialogTitle>
<DialogDescription className="text-base">
Customize your AgentGraph experience
</DialogDescription>
</DialogHeader>
<div className="flex flex-1 min-h-0">
{/* Navigation Sidebar */}
<div className="w-64 border-r bg-muted/20 p-4">
<nav className="space-y-2">
{sidebarSections.map((section) => (
<Button
key={section.id}
variant={activeSection === section.id ? "secondary" : "ghost"}
className="w-full justify-start gap-2 h-auto p-3"
onClick={() => setActiveSection(section.id)}
>
<section.icon className="h-4 w-4" />
<span className="text-sm font-medium">{section.name}</span>
</Button>
))}
</nav>
</div>
{/* Content Area */}
<div className="flex-1 min-w-0">
<ScrollArea className="h-[70vh] p-6">{renderSection()}</ScrollArea>
</div>
</div>
<Separator />
<div className="p-6 pt-4 flex justify-between items-center">
<div className="text-sm text-muted-foreground">
Changes are saved automatically
</div>
<Button onClick={() => onOpenChange(false)}>Done</Button>
</div>
</DialogContent>
</Dialog>
);
}
|