feat: auto select the first model as default model

This commit is contained in:
Henry Li
2026-01-26 17:13:34 +08:00
parent ff7065b085
commit 574dfd2b05
4 changed files with 17 additions and 8 deletions

View File

@@ -72,10 +72,18 @@ export function InputBox({
const { t } = useI18n();
const [modelDialogOpen, setModelDialogOpen] = useState(false);
const { models } = useModels();
const selectedModel = useMemo(
() => models.find((m) => m.name === context.model_name),
[context.model_name, models],
);
const selectedModel = useMemo(() => {
if (!context.model_name && models.length > 0) {
setTimeout(() => {
onContextChange?.({
...context,
model_name: models[0]!.name,
});
}, 0);
return models[0]!;
}
return models.find((m) => m.name === context.model_name);
}, [context, models, onContextChange]);
const supportThinking = useMemo(
() => selectedModel?.supports_thinking ?? false,
[selectedModel],

View File

@@ -2,10 +2,11 @@ import { useQuery } from "@tanstack/react-query";
import { loadModels } from "./api";
export function useModels() {
export function useModels({ enabled = true }: { enabled?: boolean } = {}) {
const { data, isLoading, error } = useQuery({
queryKey: ["models"],
queryFn: () => loadModels(),
enabled,
});
return { models: data ?? [], isLoading, error };
}

View File

@@ -2,9 +2,9 @@ import type { AgentThreadContext } from "../threads";
export const DEFAULT_LOCAL_SETTINGS: LocalSettings = {
context: {
model_name: "deepseek-v3.2",
model_name: undefined,
thinking_enabled: true,
is_plan_mode: false,
is_plan_mode: true,
},
layout: {
sidebar_collapsed: false,

View File

@@ -14,7 +14,7 @@ export interface AgentThread extends Thread<AgentThreadState> {}
export interface AgentThreadContext extends Record<string, unknown> {
thread_id: string;
model_name: string;
model_name: string | undefined;
thinking_enabled: boolean;
is_plan_mode: boolean;
}