From f615be61f2b9ab552ce9252d7cb6e65e74fe1474 Mon Sep 17 00:00:00 2001 From: Vikhyath Mondreti Date: Fri, 6 Feb 2026 21:26:31 -0800 Subject: [PATCH] fix ollama and vllm visibility --- .../app/api/auth/oauth/token/route.test.ts | 4 +- apps/sim/blocks/blocks/agent.ts | 30 +------- apps/sim/blocks/types.ts | 4 +- apps/sim/blocks/utils.ts | 76 +++++++++++++------ .../workflows/subblocks/visibility.test.ts | 9 +++ .../sim/lib/workflows/subblocks/visibility.ts | 7 +- 6 files changed, 74 insertions(+), 56 deletions(-) diff --git a/apps/sim/app/api/auth/oauth/token/route.test.ts b/apps/sim/app/api/auth/oauth/token/route.test.ts index 3be05f4db..a43cade34 100644 --- a/apps/sim/app/api/auth/oauth/token/route.test.ts +++ b/apps/sim/app/api/auth/oauth/token/route.test.ts @@ -255,10 +255,10 @@ describe('OAuth Token API Routes', () => { expect(mockGetOAuthToken).not.toHaveBeenCalled() }) - it('should reject API key authentication', async () => { + it('should reject non-session authentication', async () => { mockCheckSessionOrInternalAuth.mockResolvedValueOnce({ success: true, - authType: 'api_key', + authType: 'internal_jwt', userId: 'test-user-id', }) diff --git a/apps/sim/blocks/blocks/agent.ts b/apps/sim/blocks/blocks/agent.ts index bf8ec0d66..7e7b12f96 100644 --- a/apps/sim/blocks/blocks/agent.ts +++ b/apps/sim/blocks/blocks/agent.ts @@ -1,11 +1,10 @@ import { createLogger } from '@sim/logger' import { AgentIcon } from '@/components/icons' -import { isHosted } from '@/lib/core/config/feature-flags' import type { BlockConfig } from '@/blocks/types' import { AuthMode } from '@/blocks/types' +import { getApiKeyCondition } from '@/blocks/utils' import { getBaseModelProviders, - getHostedModels, getMaxTemperature, getProviderIcon, getReasoningEffortValuesForModel, @@ -17,15 +16,6 @@ import { providers, supportsTemperature, } from '@/providers/utils' - -const getCurrentOllamaModels = () => { - return useProvidersStore.getState().providers.ollama.models -} - -const getCurrentVLLMModels = () => { - return useProvidersStore.getState().providers.vllm.models -} - import { useProvidersStore } from '@/stores/providers' import type { ToolResponse } from '@/tools/types' @@ -421,23 +411,7 @@ Return ONLY the JSON array.`, password: true, connectionDroppable: false, required: true, - // Hide API key for hosted models, Ollama models, vLLM models, Vertex models (uses OAuth), and Bedrock (uses AWS credentials) - condition: isHosted - ? { - field: 'model', - value: [...getHostedModels(), ...providers.vertex.models, ...providers.bedrock.models], - not: true, // Show for all models EXCEPT those listed - } - : () => ({ - field: 'model', - value: [ - ...getCurrentOllamaModels(), - ...getCurrentVLLMModels(), - ...providers.vertex.models, - ...providers.bedrock.models, - ], - not: true, // Show for all models EXCEPT Ollama, vLLM, Vertex, and Bedrock models - }), + condition: getApiKeyCondition(), }, { id: 'memoryType', diff --git a/apps/sim/blocks/types.ts b/apps/sim/blocks/types.ts index a9904dd2e..08a716925 100644 --- a/apps/sim/blocks/types.ts +++ b/apps/sim/blocks/types.ts @@ -208,7 +208,7 @@ export interface SubBlockConfig { not?: boolean } } - | (() => { + | ((values?: Record) => { field: string value: string | number | boolean | Array not?: boolean @@ -261,7 +261,7 @@ export interface SubBlockConfig { not?: boolean } } - | (() => { + | ((values?: Record) => { field: string value: string | number | boolean | Array not?: boolean diff --git a/apps/sim/blocks/utils.ts b/apps/sim/blocks/utils.ts index eed4a5c37..8c003e0ad 100644 --- a/apps/sim/blocks/utils.ts +++ b/apps/sim/blocks/utils.ts @@ -1,6 +1,6 @@ import { isHosted } from '@/lib/core/config/feature-flags' import type { BlockOutput, OutputFieldDefinition, SubBlockConfig } from '@/blocks/types' -import { getHostedModels, providers } from '@/providers/utils' +import { getHostedModels, getProviderFromModel, providers } from '@/providers/utils' import { useProvidersStore } from '@/stores/providers/store' /** @@ -48,11 +48,54 @@ const getCurrentOllamaModels = () => { return useProvidersStore.getState().providers.ollama.models } -/** - * Helper to get current vLLM models from store - */ -const getCurrentVLLMModels = () => { - return useProvidersStore.getState().providers.vllm.models +function buildModelVisibilityCondition(model: string, shouldShow: boolean) { + if (!model) { + return { field: 'model', value: '__no_model_selected__' } + } + + return shouldShow ? { field: 'model', value: model } : { field: 'model', value: model, not: true } +} + +function shouldRequireApiKeyForModel(model: string): boolean { + const normalizedModel = model.trim().toLowerCase() + if (!normalizedModel) return false + + const hostedModels = getHostedModels() + const isHostedModel = hostedModels.some( + (hostedModel) => hostedModel.toLowerCase() === normalizedModel + ) + if (isHosted && isHostedModel) return false + + if (normalizedModel.startsWith('vertex/') || normalizedModel.startsWith('bedrock/')) { + return false + } + + if (normalizedModel.startsWith('vllm/')) { + return false + } + + const currentOllamaModels = getCurrentOllamaModels() + if (currentOllamaModels.some((ollamaModel) => ollamaModel.toLowerCase() === normalizedModel)) { + return false + } + + if (!isHosted) { + try { + const providerId = getProviderFromModel(model) + if ( + providerId === 'ollama' || + providerId === 'vllm' || + providerId === 'vertex' || + providerId === 'bedrock' + ) { + return false + } + } catch { + // If model resolution fails, fall through and require an API key. + } + } + + return true } /** @@ -60,22 +103,11 @@ const getCurrentVLLMModels = () => { * Handles hosted vs self-hosted environments and excludes providers that don't need API key. */ export function getApiKeyCondition() { - return isHosted - ? { - field: 'model', - value: [...getHostedModels(), ...providers.vertex.models, ...providers.bedrock.models], - not: true, - } - : () => ({ - field: 'model', - value: [ - ...getCurrentOllamaModels(), - ...getCurrentVLLMModels(), - ...providers.vertex.models, - ...providers.bedrock.models, - ], - not: true, - }) + return (values?: Record) => { + const model = typeof values?.model === 'string' ? values.model : '' + const shouldShow = shouldRequireApiKeyForModel(model) + return buildModelVisibilityCondition(model, shouldShow) + } } /** diff --git a/apps/sim/lib/workflows/subblocks/visibility.test.ts b/apps/sim/lib/workflows/subblocks/visibility.test.ts index 07b1f1818..b55bfad5f 100644 --- a/apps/sim/lib/workflows/subblocks/visibility.test.ts +++ b/apps/sim/lib/workflows/subblocks/visibility.test.ts @@ -156,6 +156,15 @@ describe('evaluateSubBlockCondition', () => { expect(evaluateSubBlockCondition(condition, values)).toBe(true) }) + it.concurrent('passes current values into function conditions', () => { + const condition = (values?: Record) => ({ + field: 'model', + value: typeof values?.model === 'string' ? values.model : '__no_model_selected__', + }) + const values = { model: 'ollama/gemma3:4b' } + expect(evaluateSubBlockCondition(condition, values)).toBe(true) + }) + it.concurrent('handles boolean values', () => { const condition = { field: 'enabled', value: true } const values = { enabled: true } diff --git a/apps/sim/lib/workflows/subblocks/visibility.ts b/apps/sim/lib/workflows/subblocks/visibility.ts index 74eda40fd..1ce0076b4 100644 --- a/apps/sim/lib/workflows/subblocks/visibility.ts +++ b/apps/sim/lib/workflows/subblocks/visibility.ts @@ -100,11 +100,14 @@ export function resolveCanonicalMode( * Evaluate a subblock condition against a map of raw values. */ export function evaluateSubBlockCondition( - condition: SubBlockCondition | (() => SubBlockCondition) | undefined, + condition: + | SubBlockCondition + | ((values?: Record) => SubBlockCondition) + | undefined, values: Record ): boolean { if (!condition) return true - const actual = typeof condition === 'function' ? condition() : condition + const actual = typeof condition === 'function' ? condition(values) : condition const fieldValue = values[actual.field] const valueMatch = Array.isArray(actual.value) ? fieldValue != null &&