Compare commits

...
Sign in to create a new pull request.

2 commits

Author SHA1 Message Date
Lucas Oliveira
b20da9ab58 format 2025-12-03 17:27:08 -03:00
Lucas Oliveira
97c9fdb2c6 Added alreadyConfigured as option to retrieve models 2025-12-03 16:38:52 -03:00
2 changed files with 11 additions and 8 deletions

View file

@ -1,8 +1,8 @@
import type { Dispatch, SetStateAction } from "react"; import type { Dispatch, SetStateAction } from "react";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import OllamaLogo from "@/components/icons/ollama-logo";
import { LabelInput } from "@/components/label-input"; import { LabelInput } from "@/components/label-input";
import { LabelWrapper } from "@/components/label-wrapper"; import { LabelWrapper } from "@/components/label-wrapper";
import OllamaLogo from "@/components/icons/ollama-logo";
import { useDebouncedValue } from "@/lib/debounce"; import { useDebouncedValue } from "@/lib/debounce";
import type { OnboardingVariables } from "../../api/mutations/useOnboardingMutation"; import type { OnboardingVariables } from "../../api/mutations/useOnboardingMutation";
import { useGetOllamaModelsQuery } from "../../api/queries/useGetModelsQuery"; import { useGetOllamaModelsQuery } from "../../api/queries/useGetModelsQuery";
@ -28,7 +28,9 @@ export function OllamaOnboarding({
existingEndpoint?: string; existingEndpoint?: string;
}) { }) {
const [endpoint, setEndpoint] = useState( const [endpoint, setEndpoint] = useState(
alreadyConfigured ? undefined : (existingEndpoint || `http://localhost:11434`), alreadyConfigured
? undefined
: existingEndpoint || `http://localhost:11434`,
); );
const [showConnecting, setShowConnecting] = useState(false); const [showConnecting, setShowConnecting] = useState(false);
const debouncedEndpoint = useDebouncedValue(endpoint, 500); const debouncedEndpoint = useDebouncedValue(endpoint, 500);
@ -40,7 +42,7 @@ export function OllamaOnboarding({
error: modelsError, error: modelsError,
} = useGetOllamaModelsQuery( } = useGetOllamaModelsQuery(
debouncedEndpoint ? { endpoint: debouncedEndpoint } : undefined, debouncedEndpoint ? { endpoint: debouncedEndpoint } : undefined,
{ enabled: !!debouncedEndpoint || alreadyConfigured }, { enabled: !!debouncedEndpoint || alreadyConfigured || alreadyConfigured },
); );
// Use custom hook for model selection logic // Use custom hook for model selection logic

View file

@ -1,8 +1,8 @@
import type { Dispatch, SetStateAction } from "react"; import type { Dispatch, SetStateAction } from "react";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import OpenAILogo from "@/components/icons/openai-logo";
import { LabelInput } from "@/components/label-input"; import { LabelInput } from "@/components/label-input";
import { LabelWrapper } from "@/components/label-wrapper"; import { LabelWrapper } from "@/components/label-wrapper";
import OpenAILogo from "@/components/icons/openai-logo";
import { Switch } from "@/components/ui/switch"; import { Switch } from "@/components/ui/switch";
import { import {
Tooltip, Tooltip,
@ -48,13 +48,13 @@ export function OpenAIOnboarding({
getFromEnv getFromEnv
? { apiKey: "" } ? { apiKey: "" }
: debouncedApiKey : debouncedApiKey
? { apiKey: debouncedApiKey } ? { apiKey: debouncedApiKey }
: undefined, : undefined,
{ {
// Only validate when the user opts in (env) or provides a key. // Only validate when the user opts in (env) or provides a key.
// If a key was previously configured, let the user decide to reuse or replace it // If a key was previously configured, let the user decide to reuse or replace it
// without triggering an immediate validation error. // without triggering an immediate validation error.
enabled: debouncedApiKey !== "" || getFromEnv, enabled: debouncedApiKey !== "" || getFromEnv || alreadyConfigured,
}, },
); );
// Use custom hook for model selection logic // Use custom hook for model selection logic
@ -144,7 +144,8 @@ export function OpenAIOnboarding({
/> />
{alreadyConfigured && ( {alreadyConfigured && (
<p className="text-mmd text-muted-foreground"> <p className="text-mmd text-muted-foreground">
Existing OpenAI key detected. You can reuse it or enter a new one. Existing OpenAI key detected. You can reuse it or enter a new
one.
</p> </p>
)} )}
{isLoadingModels && ( {isLoadingModels && (