feat(llm-config): remove unused useLLMConfigs hook - completely migrated to jotai + tanstack query

This commit is contained in:
CREDO23 2025-12-10 08:22:42 +00:00
parent c3dd3de6f6
commit 80d6696310
2 changed files with 8 additions and 133 deletions

View file

@ -12,8 +12,10 @@ import { OnboardHeader } from "@/components/onboard/onboard-header";
import { OnboardLLMSetup } from "@/components/onboard/onboard-llm-setup";
import { OnboardLoading } from "@/components/onboard/onboard-loading";
import { OnboardStats } from "@/components/onboard/onboard-stats";
import { useGlobalLLMConfigs, useLLMConfigs, useLLMPreferences } from "@/hooks/use-llm-configs";
import { useGlobalLLMConfigs, useLLMPreferences } from "@/hooks/use-llm-configs";
import { getBearerToken, redirectToLogin } from "@/lib/auth-utils";
import { useAtomValue } from "jotai";
import { llmConfigsAtom } from "@/atoms/llm-config/llm-config-query.atoms";
const OnboardPage = () => {
const t = useTranslations("onboard");
@ -21,7 +23,7 @@ const OnboardPage = () => {
const params = useParams();
const searchSpaceId = Number(params.search_space_id);
const { llmConfigs, loading: configsLoading, refreshConfigs } = useLLMConfigs(searchSpaceId);
const { data: llmConfigs = [], isFetching: configsLoading, refetch: refreshConfigs } = useAtomValue(llmConfigsAtom);
const { globalConfigs, loading: globalConfigsLoading } = useGlobalLLMConfigs();
const {
preferences,
@ -165,8 +167,8 @@ const OnboardPage = () => {
? t("configure_providers_and_assign_roles")
: t("complete_role_assignment")
}
onConfigCreated={refreshConfigs}
onConfigDeleted={refreshConfigs}
onConfigCreated={() => refreshConfigs()}
onConfigDeleted={() => refreshConfigs()}
onPreferencesUpdated={refreshPreferences}
/>
);
@ -257,8 +259,8 @@ const OnboardPage = () => {
setShowLLMSettings={setShowAdvancedSettings}
showPromptSettings={showPromptSettings}
setShowPromptSettings={setShowPromptSettings}
onConfigCreated={refreshConfigs}
onConfigDeleted={refreshConfigs}
onConfigCreated={() => refreshConfigs()}
onConfigDeleted={() => refreshConfigs()}
onPreferencesUpdated={refreshPreferences}
/>

View file

@ -2,7 +2,6 @@
import { useEffect, useState } from "react";
import { toast } from "sonner";
import { authenticatedFetch } from "@/lib/auth-utils";
import { UpdateLLMConfigRequest } from "@/contracts/types/llm-config.types";
export interface LLMConfig {
id: number;
@ -50,132 +49,6 @@ export interface UpdateLLMConfig {
litellm_params?: Record<string, any>;
}
export function useLLMConfigs(searchSpaceId: number | null) {
const [llmConfigs, setLlmConfigs] = useState<LLMConfig[]>([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const fetchLLMConfigs = async () => {
if (!searchSpaceId) {
setLoading(false);
return;
}
try {
setLoading(true);
const response = await authenticatedFetch(
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/llm-configs?search_space_id=${searchSpaceId}`,
{ method: "GET" }
);
if (!response.ok) {
throw new Error("Failed to fetch LLM configurations");
}
const data = await response.json();
setLlmConfigs(data);
setError(null);
} catch (err: any) {
setError(err.message || "Failed to fetch LLM configurations");
console.error("Error fetching LLM configurations:", err);
} finally {
setLoading(false);
}
};
useEffect(() => {
fetchLLMConfigs();
}, [searchSpaceId]);
const createLLMConfig = async (config: CreateLLMConfig): Promise<LLMConfig | null> => {
try {
const response = await authenticatedFetch(
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/llm-configs`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(config),
}
);
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.detail || "Failed to create LLM configuration");
}
const newConfig = await response.json();
setLlmConfigs((prev) => [...prev, newConfig]);
toast.success("LLM configuration created successfully");
return newConfig;
} catch (err: any) {
toast.error(err.message || "Failed to create LLM configuration");
console.error("Error creating LLM configuration:", err);
return null;
}
};
const deleteLLMConfig = async (id: number): Promise<boolean> => {
try {
const response = await authenticatedFetch(
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/llm-configs/${id}`,
{ method: "DELETE" }
);
if (!response.ok) {
throw new Error("Failed to delete LLM configuration");
}
setLlmConfigs((prev) => prev.filter((config) => config.id !== id));
toast.success("LLM configuration deleted successfully");
return true;
} catch (err: any) {
toast.error(err.message || "Failed to delete LLM configuration");
console.error("Error deleting LLM configuration:", err);
return false;
}
};
const updateLLMConfig = async (
id: number,
config: UpdateLLMConfigRequest["data"]
): Promise<LLMConfig | null> => {
try {
const response = await authenticatedFetch(
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/llm-configs/${id}`,
{
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(config),
}
);
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.detail || "Failed to update LLM configuration");
}
const updatedConfig = await response.json();
setLlmConfigs((prev) => prev.map((c) => (c.id === id ? updatedConfig : c)));
toast.success("LLM configuration updated successfully");
return updatedConfig;
} catch (err: any) {
toast.error(err.message || "Failed to update LLM configuration");
console.error("Error updating LLM configuration:", err);
return null;
}
};
return {
llmConfigs,
loading,
error,
createLLMConfig,
updateLLMConfig,
deleteLLMConfig,
refreshConfigs: fetchLLMConfigs,
};
}
export function useLLMPreferences(searchSpaceId: number | null) {
const [preferences, setPreferences] = useState<LLMPreferences>({});
const [loading, setLoading] = useState(true);