578d990b9c
https://www.figma.com/design/xt8O9mFeLl46C5InWwoMrN/Twenty?node-id=93653-368288&t=obTG32NRidXid4lN-0 closes https://discord.com/channels/1130383047699738754/1480990726442582086 --------- Co-authored-by: Félix Malfait <felix.malfait@gmail.com> Co-authored-by: Félix Malfait <felix@twenty.com>
24 lines
895 B
TypeScript
24 lines
895 B
TypeScript
import { isDefined } from 'twenty-shared/utils';
|
|
|
|
import { useWorkspaceAiModelAvailability } from '@/ai/hooks/useWorkspaceAiModelAvailability';
|
|
import { agentChatUserSelectedModelState } from '@/ai/states/agentChatUserSelectedModelState';
|
|
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
|
|
|
|
export const useAgentChatModelId = () => {
|
|
const { enabledModels } = useWorkspaceAiModelAvailability();
|
|
const agentChatUserSelectedModel = useAtomStateValue(
|
|
agentChatUserSelectedModelState,
|
|
);
|
|
|
|
const isUserModelAvailable =
|
|
!isDefined(agentChatUserSelectedModel) ||
|
|
enabledModels.some((model) => model.modelId === agentChatUserSelectedModel);
|
|
|
|
const selectedModelId = isUserModelAvailable
|
|
? agentChatUserSelectedModel
|
|
: null;
|
|
const modelIdForRequest = selectedModelId ?? undefined;
|
|
|
|
return { selectedModelId, modelIdForRequest };
|
|
};
|