Skip to content

SmythOS Studio: Open-Source Visual AI Agent Builder and deployable runtime stack from SmythOS. Start with an intuitive drag-and-drop workspace, extend with custom code, and deploy your agents anywhere — local, cloud, or edge — with full governance and control.

filter hidden models properly in all places where models are displayed

Forhad Hosain056c28b45709
diff --git a/packages/app/src/builder-ui/components/GenAILLM.class.ts b/packages/app/src/builder-ui/components/GenAILLM.class.ts
index 24672bc6..505a32aa 100644
--- a/packages/app/src/builder-ui/components/GenAILLM.class.ts
+++ b/packages/app/src/builder-ui/components/GenAILLM.class.ts
@@ -52,23 +52,19 @@ export class GenAILLM extends Component {
private gptSearchModels: string[];
protected async prepare() {
- const modelOptions = LLMFormController.prepareModelSelectOptionsByFeatures([
- 'text',
- 'image',
- 'audio',
- 'video',
- 'document',
- 'tools',
- 'search',
- 'reasoning',
- ]);
+ const model = this.data.model || this.defaultModel;
+
+ const modelOptions = LLMFormController.prepareModelSelectOptionsByFeatures(
+ ['text', 'image', 'audio', 'video', 'document', 'tools', 'search', 'reasoning'],
+ model,
+ );
this.defaultModel = LLMFormController.getDefaultModel(modelOptions);
- this.anthropicThinkingModels = LLMRegistry.getSortedModelsByFeatures(
- 'reasoning',
- 'anthropic',
- ).map((m) => m.entryId);
+ this.anthropicThinkingModels = LLMRegistry.getSortedModelsByFeatures({
+ features: 'reasoning',
+ providers: 'anthropic',
+ }).map((m) => m.entryId);
this.openaiReasoningModels = LLMRegistry.getModelsByFeatures('reasoning', 'openai').map(
(m) => m.entryId,
);
@@ -87,7 +83,6 @@ export class GenAILLM extends Component {
);
modelOptions.unshift('Echo');
- const model = this.data.model || this.defaultModel;
//prevent losing the previously set model
if (model && ![...modelOptions.map((item) => item?.value || item)].includes(model)) {
@@ -101,15 +96,7 @@ export class GenAILLM extends Component {
// TODO: set warning if the model is not available
//remove undefined models
- this.modelOptions = modelOptions.filter((item) => {
- if (!item) return false;
-
- // Keep the currently selected model even if it's hidden
- if (item?.value === model) return true;
-
- // Otherwise, filter out hidden models
- return !item?.hidden;
- });
+ this.modelOptions = modelOptions.filter((item) => item);
this.setModelParams(model);
diff --git a/packages/app/src/builder-ui/helpers/LLMFormController.helper.ts b/packages/app/src/builder-ui/helpers/LLMFormController.helper.ts
index 33e71481..9fc1e209 100644
--- a/packages/app/src/builder-ui/helpers/LLMFormController.helper.ts
+++ b/packages/app/src/builder-ui/helpers/LLMFormController.helper.ts
@@ -320,11 +320,17 @@ export class LLMFormController {
* - badge: HTML string with both status and capability badges
* - tags: Array of model tags for sorting/filtering```````````````````
*/
- public static prepareModelSelectOptionsByFeatures(targetFeatures: string[]) {
+ public static prepareModelSelectOptionsByFeatures(
+ targetFeatures: string[],
+ selectedModel?: string,
+ ) {
try {
let modelOptions = [];
- const models = LLMRegistry.getSortedModelsByFeatures(targetFeatures);
+ const models = LLMRegistry.getSortedModelsByFeatures({
+ features: targetFeatures,
+ selectedModel,
+ });
for (const model of models) {
let tags = model?.tags || [];
@@ -344,7 +350,6 @@ export class LLMFormController {
badge: `<span class="model-name-badge"><span class="model-name">${model?.label}</span> <span class="all-badges">${statusBadges}</span></span> <span class="float-right">${capabilityBadges}</span>`,
tags,
default: model?.default || false,
- hidden: model?.hidden || false,
});
}
diff --git a/packages/app/src/react/features/agent-settings/components/OverviewWidgetsContainer/index.tsx b/packages/app/src/react/features/agent-settings/components/OverviewWidgetsContainer/index.tsx
index 35db4b0e..bdc8b1be 100644
--- a/packages/app/src/react/features/agent-settings/components/OverviewWidgetsContainer/index.tsx
+++ b/packages/app/src/react/features/agent-settings/components/OverviewWidgetsContainer/index.tsx
@@ -29,6 +29,17 @@ import {
import { FaCheck } from 'react-icons/fa';
import * as Yup from 'yup';
+/**
+ * Form values interface
+ * Represents the shape of form data for agent settings
+ */
+interface FormValues {
+ chatGptModel?: string;
+ behavior?: string;
+ name?: string;
+ shortDescription?: string;
+}
+
// Create the context type
interface WidgetsContextType {
formik: ReturnType<typeof useFormik>;
@@ -68,13 +79,6 @@ export const useWidgetsContext = () => {
return context;
};
-interface FormValues {
- chatGptModel?: string;
- behavior?: string;
- name?: string;
- shortDescription?: string;
-}
-
const OverviewWidgetsContainer = ({ isWriteAccess }: { isWriteAccess: boolean }) => {
const queryClient = useQueryClient();
const { agentQuery, agentId, settingsQuery, workspace } = useAgentSettingsCtx();
@@ -152,12 +156,19 @@ const OverviewWidgetsContainer = ({ isWriteAccess }: { isWriteAccess: boolean })
.getState()
.init()
.finally(() => {
+ // Get the current model from settings data
+ // Since formik.values.chatGptModel is empty at this point, we access the source data directly
+ const currentModelValue = settingsQuery.data?.settings?.chatGptModel || '';
+
const llmModels: {
label: string;
value: string;
tags: string[];
default?: boolean;
- }[] = LLMRegistry.getSortedModelsByFeatures('tools').map((model) => ({
+ }[] = LLMRegistry.getSortedModelsByFeatures({
+ features: 'tools',
+ selectedModel: currentModelValue,
+ }).map((model) => ({
label: model.label,
value: model.entryId,
tags: model.tags,
@@ -175,7 +186,7 @@ const OverviewWidgetsContainer = ({ isWriteAccess }: { isWriteAccess: boolean })
setIsLLMModelsLoading(false);
});
- }, []); // Empty dependency array means this runs once on mount
+ }, [settingsQuery.data]); // Re-run when settings data becomes available
//* we deprecated the agent embodiments settings and instead we are using the agent settings
// for backward compatibility we will show the agent embodiment settings in case the agent settings are not available (empty)
diff --git a/packages/app/src/react/features/agent-settings/dialogs/ChatBot.tsx b/packages/app/src/react/features/agent-settings/dialogs/ChatBot.tsx
index 6ff29d23..7e8ed151 100644
--- a/packages/app/src/react/features/agent-settings/dialogs/ChatBot.tsx
+++ b/packages/app/src/react/features/agent-settings/dialogs/ChatBot.tsx
@@ -26,19 +26,13 @@ import { EMBODIMENT_TYPE } from '@react/shared/enums';
import { Agent } from '@react/shared/types/agent-data.types';
import { extractError } from '@react/shared/utils/errors';
import { cn, validateDomains, validateURL } from '@react/shared/utils/utils';
+import { Tooltip, TooltipContent, TooltipTrigger } from '@src/react/shared/components/ui/tooltip';
import { ChatbotEmbodimentData } from '@src/react/shared/types/api-results.types';
import { errorToast, successToast, warningToast } from '@src/shared/components/toast';
import { Observability } from '@src/shared/observability';
import classNames from 'classnames';
-import { Tooltip, TooltipContent, TooltipTrigger } from '@src/react/shared/components/ui/tooltip';
import { Info } from 'lucide-react';
-// const CHATGPT_MODELS_V2 = LLMRegistry.getSortedModelsByFeatures('tools').map((model) => ({
-// name: model.label,
-// value: model.entryId,
-// tags: model.tags,
-// }));
-
// #region Temporary Badges
const TEMP_BADGES = {
enterprise: true,
diff --git a/packages/app/src/react/features/ai-chat/components/header.tsx b/packages/app/src/react/features/ai-chat/components/header.tsx
index fe111f3c..ffc68524 100644
--- a/packages/app/src/react/features/ai-chat/components/header.tsx
+++ b/packages/app/src/react/features/ai-chat/components/header.tsx
@@ -95,15 +95,16 @@ export const ChatHeader: FC = () => {
.getState()
.init()
.finally(() => {
- const models: Array<ILLMModels> = LLMRegistry.getSortedModelsByFeatures('tools').map(
- (model) => ({
- label: model.label,
- value: model.entryId,
- tags: model.tags,
- default: model?.default || false,
- provider: model.provider || '',
- }),
- );
+ const models: Array<ILLMModels> = LLMRegistry.getSortedModelsByFeatures({
+ features: 'tools',
+ selectedModel: currentModel,
+ }).map((model) => ({
+ label: model.label,
+ value: model.entryId,
+ tags: model.tags,
+ default: model?.default || false,
+ provider: model.provider || '',
+ }));
setLlmModels(models);
setIsModelsLoading(false);
diff --git a/packages/app/src/react/features/vault/components/create-user-custom-model-modal.tsx b/packages/app/src/react/features/vault/components/create-user-custom-model-modal.tsx
index ae54a2a0..4947c5eb 100644
--- a/packages/app/src/react/features/vault/components/create-user-custom-model-modal.tsx
+++ b/packages/app/src/react/features/vault/components/create-user-custom-model-modal.tsx
@@ -146,7 +146,10 @@ export function CreateUserCustomModelModal({
const prevIsOpenRef = useRef(isOpen);
const fallbackOptions = useMemo(() => {
- return LLMRegistry.getSortedModelsByFeatures('tools').map((model) => {
+ return LLMRegistry.getSortedModelsByFeatures({
+ features: 'tools',
+ selectedModel: editModel?.fallbackLLM,
+ }).map((model) => {
let badge = getTempBadge(model.tags);
badge = badge ? ' (' + badge + ')' : '';
return {
@@ -154,7 +157,7 @@ export function CreateUserCustomModelModal({
name: model.label + badge, // Add tags like "(Personal)" as shown in Default LLM section
};
});
- }, []);
+ }, [editModel?.fallbackLLM]);
/**
* Memoize serialized editModel to properly track deep changes
diff --git a/packages/app/src/shared/services/LLMRegistry.service.ts b/packages/app/src/shared/services/LLMRegistry.service.ts
index 1487b53f..b397fcfe 100644
--- a/packages/app/src/shared/services/LLMRegistry.service.ts
+++ b/packages/app/src/shared/services/LLMRegistry.service.ts
@@ -92,6 +92,7 @@ export class LLMRegistry {
public static getModelsByFeatures(
features: string | string[],
providers?: string | string[],
+ selectedModel?: string,
): LLMModel[] {
const models = this.getModels();
const targetFeatures = Array.isArray(features) ? features : [features];
@@ -110,6 +111,12 @@ export class LLMRegistry {
'features' in model &&
Array.isArray(model.features)
) {
+ // We need to hide the model if it is hidden, but not the selected one.
+ if (model?.hidden && selectedModel !== model.modelId) {
+ continue;
+ }
+
+ // #region Features filtering
// Check if model supports at least one of the target features
const hasRequiredFeature = targetFeatures.some((feature) =>
(model.features as string[]).includes(feature),
@@ -118,7 +125,9 @@ export class LLMRegistry {
if (!hasRequiredFeature) {
continue;
}
+ // #endregion Features filtering
+ // #region Providers filtering
// If no providers specified, include all models with the feature(s)
if (!normalizedProviders) {
modelEntries.push([key, model]);
@@ -130,6 +139,7 @@ export class LLMRegistry {
if (normalizedProviders.includes(modelProvider)) {
modelEntries.push([key, model]);
}
+ // #endregion Providers filtering
}
}
@@ -149,11 +159,16 @@ export class LLMRegistry {
* Can be a single provider string or array of providers.
* @returns Sorted array of LLMModel objects that support the specified feature(s)
*/
- public static getSortedModelsByFeatures(
- features: string | string[],
- providers?: string | string[],
- ): LLMModel[] {
- const models = this.getModelsByFeatures(features, providers);
+ public static getSortedModelsByFeatures({
+ features,
+ providers,
+ selectedModel,
+ }: {
+ features: string | string[];
+ providers?: string | string[];
+ selectedModel?: string;
+ }): LLMModel[] {
+ const models = this.getModelsByFeatures(features, providers, selectedModel);
return this.sortModels(models);
}