|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { useEffect, useState } from "react"; |
| 4 | +import { useForm } from "react-hook-form"; |
| 5 | +import { zodResolver } from "@hookform/resolvers/zod"; |
| 6 | +import { z } from "zod"; |
| 7 | +import { Sidebar } from "@/components/layout/sidebar"; |
| 8 | +import { Input } from "@/components/ui/input"; |
| 9 | +import { Switch } from "@/components/ui/switch"; |
| 10 | +import { Button } from "@/components/ui/button"; |
| 11 | +import { useChatStore } from "@/lib/store/chat-store"; |
| 12 | + |
| 13 | +const formSchema = z.object({ |
| 14 | + model: z.string().min(1), |
| 15 | + temperature: z.coerce.number().min(0).max(2), |
| 16 | + streaming: z.boolean(), |
| 17 | + safeMode: z.boolean(), |
| 18 | + telemetry: z.boolean() |
| 19 | +}); |
| 20 | + |
| 21 | +type FormData = z.infer<typeof formSchema>; |
| 22 | + |
| 23 | +export default function SettingsPage() { |
| 24 | + const { config, setConfig } = useChatStore(); |
| 25 | + const [status, setStatus] = useState<string>(""); |
| 26 | + |
| 27 | + const form = useForm<FormData>({ |
| 28 | + resolver: zodResolver(formSchema), |
| 29 | + defaultValues: config |
| 30 | + }); |
| 31 | + |
| 32 | + useEffect(() => { |
| 33 | + form.reset(config); |
| 34 | + }, [config, form]); |
| 35 | + |
| 36 | + const onSubmit = form.handleSubmit(async (values) => { |
| 37 | + const res = await fetch("/api/config", { |
| 38 | + method: "PUT", |
| 39 | + headers: { "Content-Type": "application/json" }, |
| 40 | + body: JSON.stringify(values) |
| 41 | + }); |
| 42 | + |
| 43 | + if (!res.ok) { |
| 44 | + setStatus("Failed to save settings."); |
| 45 | + return; |
| 46 | + } |
| 47 | + |
| 48 | + setConfig(values); |
| 49 | + setStatus("Configuration saved securely."); |
| 50 | + }); |
| 51 | + |
| 52 | + return ( |
| 53 | + <main className="flex h-screen overflow-hidden"> |
| 54 | + <Sidebar /> |
| 55 | + <section className="flex-1 p-4 md:p-6"> |
| 56 | + <div className="mx-auto max-w-2xl rounded-xl border border-border bg-panel p-6"> |
| 57 | + <h2 className="mb-1 text-xl font-semibold">ARIV Configuration</h2> |
| 58 | + <p className="mb-6 text-sm text-muted">Manage model behavior and safety settings.</p> |
| 59 | + |
| 60 | + <form onSubmit={onSubmit} className="space-y-5"> |
| 61 | + <div> |
| 62 | + <label className="mb-2 block text-sm">Model Name</label> |
| 63 | + <Input {...form.register("model")} /> |
| 64 | + </div> |
| 65 | + |
| 66 | + <div> |
| 67 | + <label className="mb-2 block text-sm">Temperature</label> |
| 68 | + <Input type="number" step="0.1" min="0" max="2" {...form.register("temperature")} /> |
| 69 | + </div> |
| 70 | + |
| 71 | + <div className="flex items-center justify-between rounded-md border border-border p-3"> |
| 72 | + <span className="text-sm">Enable Streaming Responses</span> |
| 73 | + <Switch checked={form.watch("streaming")} onCheckedChange={(v) => form.setValue("streaming", v)} /> |
| 74 | + </div> |
| 75 | + |
| 76 | + <div className="flex items-center justify-between rounded-md border border-border p-3"> |
| 77 | + <span className="text-sm">Safe Mode (recommended)</span> |
| 78 | + <Switch checked={form.watch("safeMode")} onCheckedChange={(v) => form.setValue("safeMode", v)} /> |
| 79 | + </div> |
| 80 | + |
| 81 | + <div className="flex items-center justify-between rounded-md border border-border p-3"> |
| 82 | + <span className="text-sm">Telemetry</span> |
| 83 | + <Switch checked={form.watch("telemetry")} onCheckedChange={(v) => form.setValue("telemetry", v)} /> |
| 84 | + </div> |
| 85 | + |
| 86 | + <Button type="submit">Save Configuration</Button> |
| 87 | + {status ? <p className="text-sm text-muted">{status}</p> : null} |
| 88 | + </form> |
| 89 | + </div> |
| 90 | + </section> |
| 91 | + </main> |
| 92 | + ); |
| 93 | +} |
0 commit comments