refactor(onboarding, model-connections): enhance onboarding logic and streamline model connection handling by integrating chat model checks and improving state management

This commit is contained in:
Anish Sarkar 2026-06-13 20:48:24 +05:30
parent ab5423d2d2
commit 97f004e7e1
4 changed files with 97 additions and 130 deletions

View file

@ -1,8 +1,29 @@
export function isLlmOnboardingComplete(
agentLlmId: number | null | undefined,
hasGlobalConfigs: boolean
): boolean {
if (agentLlmId === null || agentLlmId === undefined) return false;
if (agentLlmId === 0) return hasGlobalConfigs;
return true;
import type { ConnectionRead } from "@/contracts/types/model-connections.types";
export function hasEnabledChatModel(connections: ConnectionRead[]): boolean {
return connections.some(
(connection) =>
connection.enabled &&
connection.models.some((model) => model.enabled && Boolean(model.supports_chat))
);
}
export function isLlmOnboardingComplete(
chatModelId: number | null | undefined,
globalConnections: ConnectionRead[],
searchSpaceConnections: ConnectionRead[]
): boolean {
const connections = [...globalConnections, ...searchSpaceConnections];
const resolvedChatModelId = chatModelId ?? 0;
if (resolvedChatModelId === 0) {
return hasEnabledChatModel(connections);
}
return connections.some((connection) =>
connection.models.some(
(model) =>
model.id === resolvedChatModelId && model.enabled && Boolean(model.supports_chat)
)
);
}