fix ollama and vllm visibility

This commit is contained in:
Vikhyath Mondreti
2026-02-06 21:26:31 -08:00
parent c9691fc437
commit f615be61f2
6 changed files with 74 additions and 56 deletions

View File

@@ -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',
})

View File

@@ -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',

View File

@@ -208,7 +208,7 @@ export interface SubBlockConfig {
not?: boolean
}
}
| (() => {
| ((values?: Record<string, unknown>) => {
field: string
value: string | number | boolean | Array<string | number | boolean>
not?: boolean
@@ -261,7 +261,7 @@ export interface SubBlockConfig {
not?: boolean
}
}
| (() => {
| ((values?: Record<string, unknown>) => {
field: string
value: string | number | boolean | Array<string | number | boolean>
not?: boolean

View File

@@ -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<string, unknown>) => {
const model = typeof values?.model === 'string' ? values.model : ''
const shouldShow = shouldRequireApiKeyForModel(model)
return buildModelVisibilityCondition(model, shouldShow)
}
}
/**

View File

@@ -156,6 +156,15 @@ describe('evaluateSubBlockCondition', () => {
expect(evaluateSubBlockCondition(condition, values)).toBe(true)
})
it.concurrent('passes current values into function conditions', () => {
const condition = (values?: Record<string, unknown>) => ({
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 }

View File

@@ -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<string, unknown>) => SubBlockCondition)
| undefined,
values: Record<string, unknown>
): 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 &&