fix(agent): move route selector to settings
This commit is contained in:
@@ -7,9 +7,11 @@ import {
|
||||
resetAssistantSystemPrompt,
|
||||
setAssistantEnabled,
|
||||
setAssistantName,
|
||||
setAssistantModelRoute,
|
||||
setAssistantSystemPrompt,
|
||||
} from "@/app/settings/assistant-actions";
|
||||
import { DEFAULT_ASSISTANT_NAME, MAX_ASSISTANT_NAME_LENGTH } from "@/lib/assistant-config";
|
||||
import type { AssistantModelRoute } from "@/lib/llm/models";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
@@ -17,15 +19,29 @@ import { Switch } from "@/components/ui/switch";
|
||||
type Props = {
|
||||
enabled: boolean;
|
||||
name: string;
|
||||
modelRoute: string | null;
|
||||
systemPrompt: string | null;
|
||||
defaultSystemPrompt: string;
|
||||
};
|
||||
|
||||
export function AssistantSettings({ enabled, name, systemPrompt, defaultSystemPrompt }: Props) {
|
||||
function normalizeAssistantModelRoute(value: string | null): AssistantModelRoute {
|
||||
return value === "uncensored" ? "uncensored" : "auto";
|
||||
}
|
||||
|
||||
export function AssistantSettings({
|
||||
enabled,
|
||||
name,
|
||||
modelRoute,
|
||||
systemPrompt,
|
||||
defaultSystemPrompt,
|
||||
}: Props) {
|
||||
const [isPending, startTransition] = useTransition();
|
||||
const router = useRouter();
|
||||
|
||||
const effectivePrompt = systemPrompt ?? defaultSystemPrompt;
|
||||
const [selectedRoute, setSelectedRoute] = useState<AssistantModelRoute>(() =>
|
||||
normalizeAssistantModelRoute(modelRoute),
|
||||
);
|
||||
const [savedName, setSavedName] = useState(name);
|
||||
const [draftName, setDraftName] = useState(name);
|
||||
const [savedPrompt, setSavedPrompt] = useState(systemPrompt);
|
||||
@@ -45,6 +61,16 @@ export function AssistantSettings({ enabled, name, systemPrompt, defaultSystemPr
|
||||
});
|
||||
}
|
||||
|
||||
function changeModelRoute(nextRoute: string) {
|
||||
const route = normalizeAssistantModelRoute(nextRoute);
|
||||
setSelectedRoute(route);
|
||||
|
||||
startTransition(async () => {
|
||||
await setAssistantModelRoute(route);
|
||||
router.refresh();
|
||||
});
|
||||
}
|
||||
|
||||
function saveName() {
|
||||
const next = draftName.trim();
|
||||
if (!next) return;
|
||||
@@ -105,6 +131,29 @@ export function AssistantSettings({ enabled, name, systemPrompt, defaultSystemPr
|
||||
/>
|
||||
</label>
|
||||
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="min-w-0">
|
||||
<label htmlFor="assistant-model-route" className="text-sm font-medium">
|
||||
Model route
|
||||
</label>
|
||||
<p className="muted text-[12px] mt-0.5">
|
||||
Choose the default router family for your assistant. Individual models can still be
|
||||
picked from the chat panel.
|
||||
</p>
|
||||
</div>
|
||||
<select
|
||||
id="assistant-model-route"
|
||||
aria-label="Assistant model route"
|
||||
value={selectedRoute}
|
||||
disabled={isPending}
|
||||
onChange={(event) => changeModelRoute(event.target.value)}
|
||||
className="input h-10"
|
||||
>
|
||||
<option value="auto">Auto</option>
|
||||
<option value="uncensored">Uncensored</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="flex items-end justify-between gap-3">
|
||||
<div className="min-w-0 flex-1">
|
||||
|
||||
Reference in New Issue
Block a user