Skip to content

Commit 1ae4726

Browse files
committed
fix(models): stop resolving sim-auto to ollama outside the model router
sim-auto is a pseudo-model that only the agent, router and evaluator handlers resolve, through the model router, at execution time. Every other provider lookup fell through to getProviderFromModel's unknown-model default and treated it as an Ollama model: - translate and guardrails offered Auto but never resolve it, so a run sent model sim-auto to provider ollama (or a provider allowlist refused it as ollama); editing validation accepted it there and the catalog advertised it - assertModelAllowed refused sim-auto as provider ollama under allowedModelProviders, while the client gate allowed it - the usage breakdown gave sim-auto rows the Ollama mark and merged BYOK sim-auto usage into the Ollama row - the editor's API-key reset, tool-usage control and attachment cap looked up ollama for it (hiding the tool-usage control for Auto), and the first two threw uncaught on a blacklisted model - getPiModelOptions and the router/evaluator serialization looked it up on every call, logging a provider warning each time Now: - getProviderFromModel throws an explicit error for sim-auto instead of answering ollama; the guardrails Vertex-credential check skips sim-auto so it cannot reach that throw - DEFAULT_BLOCK_MODEL (providers/default-model.ts, dependency-free) is the one source for the agent/router/evaluator default and the executor's DEFAULT_MODELs, which are what sim-auto falls back to - getSerializedModelProviderId becomes resolveModelProviderId: an unset, reference or sim-auto model answers as DEFAULT_BLOCK_MODEL, and it still never throws. The agent block (dropping its own special case) and the three editor call sites use it, so they no longer throw - getModelOptions no longer includes Auto; getModelOptionsWithAuto (router, evaluator) and getAgentModelOptions do. Editing validation reads one declarative MODEL_OPTION_SOURCES map instead of comparing option functions: only getModelOptions and getModelOptionsWithAuto fields are checked against the catalog, sim-auto is accepted only where the source offers Auto on hosted Sim, and a reference or {{ENV_VAR}} value is passed through (router and evaluator used to reject them). The agent's model field stays unvalidated, as before - assertModelAllowed skips the provider allowlist for sim-auto (the router gates each pool candidate) but still applies deniedModels - the usage breakdown attributes sim-auto to its own key, labelled Auto, in the model and BYOK dimensions; every other model is attributed as before
1 parent ae97162 commit 1ae4726

29 files changed

Lines changed: 478 additions & 94 deletions

File tree

‎apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/file-upload/file-upload.tsx‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { useActiveCanonicalSubBlockValue } from '@/app/workspace/[workspaceId]/w
2828
import { useResourceFolders } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-resource-folders'
2929
import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-sub-block-value'
3030
import { useActiveSearchTarget } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/providers/active-search-target-provider'
31+
import { resolveModelProviderId } from '@/blocks/utils'
3132
import { invalidateWorkspaceFileReads } from '@/hooks/queries/utils/workspace-file-cache'
3233
import {
3334
workspaceFileListParams,
@@ -42,7 +43,6 @@ import {
4243
} from '@/hooks/queries/workspace-files'
4344
import { useSearchFilterValue } from '@/hooks/use-search-filter-value'
4445
import { getProviderAttachmentMaxBytes } from '@/providers/attachments'
45-
import { getProviderFromModel } from '@/providers/utils'
4646
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
4747
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
4848

@@ -322,11 +322,7 @@ export function FileUpload({
322322
const maxSizeInBytes = useMemo(() => {
323323
const fallback = maxSize * 1024 * 1024
324324
if (typeof modelValue !== 'string' || !modelValue) return fallback
325-
try {
326-
return Math.max(fallback, getProviderAttachmentMaxBytes(getProviderFromModel(modelValue)))
327-
} catch {
328-
return fallback
329-
}
325+
return Math.max(fallback, getProviderAttachmentMaxBytes(resolveModelProviderId(modelValue)))
330326
}, [modelValue, maxSize])
331327
const maxSizeLabel = `${Math.round(maxSizeInBytes / (1024 * 1024))}MB`
332328

‎apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/tool-input.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { StoredTool } from '@/app/workspace/[workspaceId]/w/[workflowId]/co
33
import {
44
isAgentToolBlock,
55
isCustomToolAlreadySelected,
6+
supportsToolUsageControlForModel,
67
} from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/utils'
78

89
describe('isAgentToolBlock', () => {
@@ -47,3 +48,15 @@ describe('already-selected checks', () => {
4748
).toBe(false)
4849
})
4950
})
51+
52+
describe('supportsToolUsageControlForModel', () => {
53+
it('offers the control for Auto, which falls back to a provider that supports it', () => {
54+
expect(supportsToolUsageControlForModel('agent', 'sim-auto')).toBe(true)
55+
})
56+
57+
it('offers it for a supporting provider and never without a model', () => {
58+
expect(supportsToolUsageControlForModel('agent', 'claude-sonnet-5-5')).toBe(true)
59+
expect(supportsToolUsageControlForModel('agent', '')).toBe(false)
60+
expect(supportsToolUsageControlForModel('mothership', '')).toBe(true)
61+
})
62+
})

‎apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/tool-input.tsx‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ import {
7272
isCustomToolAlreadySelected,
7373
isMcpToolAlreadySelected,
7474
isWorkflowAlreadySelected,
75+
supportsToolUsageControlForModel,
7576
} from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/utils'
7677
import { getActiveWorkflowSearchHighlight } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/workflow-search-highlight'
7778
import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-sub-block-value'
@@ -105,8 +106,7 @@ import { useCollaborativeWorkflow } from '@/hooks/use-collaborative-workflow'
105106
import { useOperationAccess } from '@/hooks/use-operation-access'
106107
import { usePermissionConfig } from '@/hooks/use-permission-config'
107108
import { useSettingsNavigation } from '@/hooks/use-settings-navigation'
108-
import { supportsForcedToolUse, supportsToolUsageControl } from '@/providers/models'
109-
import { getProviderFromModel } from '@/providers/utils'
109+
import { supportsForcedToolUse } from '@/providers/models'
110110
import type { ActiveSearchTarget } from '@/stores/panel/editor/store'
111111
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
112112
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
@@ -603,9 +603,7 @@ export const ToolInput = memo(function ToolInput({
603603

604604
const modelValue = useSubBlockStore((state) => state.getValue(blockId, 'model'))
605605
const model = typeof modelValue === 'string' ? modelValue : ''
606-
const provider = model ? getProviderFromModel(model) : ''
607-
const supportsToolControl =
608-
blockType === 'mothership' || (provider ? supportsToolUsageControl(provider) : false)
606+
const supportsToolControl = supportsToolUsageControlForModel(blockType, model)
609607
const supportsForce = blockType === 'mothership' || supportsForcedToolUse(model)
610608

611609
const {

‎apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/utils.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { stripVersionSuffix } from '@sim/utils/string'
22
import type { StoredTool } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/types'
33
import type { BlockConfig } from '@/blocks/types'
4+
import { resolveModelProviderId } from '@/blocks/utils'
5+
import { supportsToolUsageControl } from '@/providers/models'
46

57
/**
68
* Core blocks the agent tool picker offers even though they are not
@@ -71,3 +73,13 @@ export function isWorkflowAlreadySelected(
7173
(tool) => tool.type === 'workflow_input' && tool.params?.workflowId === workflowId
7274
)
7375
}
76+
77+
/**
78+
* Whether the tool picker offers the per-tool usage control (auto, force, none) for the
79+
* block's model. Sim Chat always does; any other block asks its model's provider.
80+
*/
81+
export function supportsToolUsageControlForModel(blockType: string, model: string): boolean {
82+
if (blockType === 'mothership') return true
83+
if (!model) return false
84+
return supportsToolUsageControl(resolveModelProviderId(model))
85+
}

‎apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-sub-block-value.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { isEqual } from 'es-toolkit'
44
import { useShallow } from 'zustand/react/shallow'
55
import { useStoreWithEqualityFn } from 'zustand/traditional'
66
import { isMcpRuntimeReference } from '@/lib/mcp/operation-policy'
7+
import { resolveModelProviderId } from '@/blocks/utils'
78
import { useCollaborativeWorkflow } from '@/hooks/use-collaborative-workflow'
8-
import { getProviderFromModel } from '@/providers/utils'
99
import { useWorkflowDiffStore } from '@/stores/workflow-diff/store'
1010
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
1111
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
@@ -193,8 +193,8 @@ export function useSubBlockValue<T = any>(
193193
const currentApiKeyValue = useSubBlockStore.getState().getValue(blockId, 'apiKey')
194194
if (currentApiKeyValue && currentApiKeyValue !== '') {
195195
const oldModelValue = storeValue as string
196-
const oldProvider = oldModelValue ? getProviderFromModel(oldModelValue) : null
197-
const newProvider = getProviderFromModel(newValue)
196+
const oldProvider = oldModelValue ? resolveModelProviderId(oldModelValue) : null
197+
const newProvider = resolveModelProviderId(newValue)
198198
if (oldProvider !== newProvider) {
199199
collaborativeSetSubblockValue(blockId, 'apiKey', '')
200200
}

‎apps/sim/blocks/blocks/agent.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,16 @@ describe('AgentBlock', () => {
112112
})
113113
})
114114
})
115+
116+
describe('tools.config.tool function', () => {
117+
const toolFunction = AgentBlock.tools.config?.tool
118+
119+
it('records the provider sim-auto falls back to, since it has none of its own', () => {
120+
expect(toolFunction?.({ model: 'sim-auto' })).toBe('anthropic')
121+
})
122+
123+
it('falls back to the same provider when no model is set', () => {
124+
expect(toolFunction?.({})).toBe('anthropic')
125+
})
126+
})
115127
})

‎apps/sim/blocks/blocks/agent.ts‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import {
88
getAgentModelOptions,
99
getModelCapabilityCondition,
1010
getProviderCredentialSubBlocks,
11-
getSerializedModelProviderId,
1211
normalizeFileInput,
1312
RESPONSE_FORMAT_WAND_CONFIG,
13+
resolveModelProviderId,
1414
} from '@/blocks/utils'
15+
import { DEFAULT_BLOCK_MODEL } from '@/providers/default-model'
1516
import {
1617
getBaseModelProviders,
1718
getEvaluationModels,
@@ -24,15 +25,11 @@ import {
2425
getReasoningEffortValuesForModel,
2526
getThinkingLevelsForModel,
2627
getVerbosityValuesForModel,
27-
isAutoModel,
2828
supportsTemperature,
2929
} from '@/providers/models'
3030

3131
const logger = createLogger('AgentBlock')
3232

33-
/** Model the agent block falls back to when `model` is unset or the auto pseudo-model. */
34-
const AGENT_FALLBACK_MODEL = 'claude-sonnet-5-5'
35-
3633
const MODELS_WITH_REASONING_EFFORT = getModelsWithReasoningEffort()
3734
const MODELS_WITH_VERBOSITY = getModelsWithVerbosity()
3835
const MODELS_WITH_THINKING = getModelsWithThinking()
@@ -130,7 +127,7 @@ Return ONLY the JSON array.`,
130127
type: 'combobox',
131128
placeholder: 'Type or select a model...',
132129
required: true,
133-
defaultValue: 'claude-sonnet-5-5',
130+
defaultValue: DEFAULT_BLOCK_MODEL,
134131
options: getAgentModelOptions,
135132
commandSearchable: true,
136133
},
@@ -428,10 +425,7 @@ Return ONLY the JSON array.`,
428425
],
429426
config: {
430427
tool: (params: Record<string, any>) => {
431-
const model = params.model || AGENT_FALLBACK_MODEL
432-
// sim-auto has no provider of its own until the pool resolves it at execution time.
433-
const lookupModel = isAutoModel(model) ? AGENT_FALLBACK_MODEL : model
434-
return getSerializedModelProviderId(lookupModel, AGENT_FALLBACK_MODEL)
428+
return resolveModelProviderId(params.model)
435429
},
436430
params: (params: Record<string, any>) => {
437431
const normalizedFiles = normalizeFileInput(params.files)

‎apps/sim/blocks/blocks/evaluator.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import { getModelFallbackSubBlock, MODEL_FALLBACK_INPUTS } from '@/blocks/model-
44
import type { BlockConfig, ParamType } from '@/blocks/types'
55
import {
66
BEDROCK_SAVED_CREDENTIAL_INPUTS,
7-
getModelOptions,
7+
getModelOptionsWithAuto,
88
getProviderCredentialSubBlocks,
9-
getSerializedModelProviderId,
109
PROVIDER_CREDENTIAL_INPUTS,
10+
resolveModelProviderId,
1111
} from '@/blocks/utils'
12+
import { DEFAULT_BLOCK_MODEL } from '@/providers/default-model'
1213

1314
const logger = createLogger('EvaluatorBlock')
1415

@@ -168,8 +169,8 @@ export const EvaluatorBlock: BlockConfig = {
168169
type: 'combobox',
169170
placeholder: 'Type or select a model...',
170171
required: true,
171-
defaultValue: 'claude-sonnet-5-5',
172-
options: getModelOptions,
172+
defaultValue: DEFAULT_BLOCK_MODEL,
173+
options: getModelOptionsWithAuto,
173174
},
174175
...getProviderCredentialSubBlocks({ bedrockSavedCredential: true }),
175176
getModelFallbackSubBlock(),
@@ -236,7 +237,7 @@ export const EvaluatorBlock: BlockConfig = {
236237
'deepseek_reasoner',
237238
],
238239
config: {
239-
tool: (params: Record<string, any>) => getSerializedModelProviderId(params.model),
240+
tool: (params: Record<string, any>) => resolveModelProviderId(params.model),
240241
},
241242
},
242243
inputs: {

‎apps/sim/blocks/blocks/router.ts‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import { getModelFallbackSubBlock, MODEL_FALLBACK_INPUTS } from '@/blocks/model-
33
import { AuthMode, type BlockConfig } from '@/blocks/types'
44
import {
55
BEDROCK_SAVED_CREDENTIAL_INPUTS,
6-
getModelOptions,
6+
getModelOptionsWithAuto,
77
getProviderCredentialSubBlocks,
8-
getSerializedModelProviderId,
98
PROVIDER_CREDENTIAL_INPUTS,
9+
resolveModelProviderId,
1010
} from '@/blocks/utils'
11+
import { DEFAULT_BLOCK_MODEL } from '@/providers/default-model'
1112

1213
interface TargetBlock {
1314
id: string
@@ -161,8 +162,8 @@ export const RouterBlock: BlockConfig = {
161162
type: 'combobox',
162163
placeholder: 'Type or select a model...',
163164
required: true,
164-
defaultValue: 'claude-sonnet-5-5',
165-
options: getModelOptions,
165+
defaultValue: DEFAULT_BLOCK_MODEL,
166+
options: getModelOptionsWithAuto,
166167
},
167168
...getProviderCredentialSubBlocks({ bedrockSavedCredential: true }),
168169
getModelFallbackSubBlock(),
@@ -194,7 +195,7 @@ export const RouterBlock: BlockConfig = {
194195
'deepseek_reasoner',
195196
],
196197
config: {
197-
tool: (params: Record<string, any>) => getSerializedModelProviderId(params.model),
198+
tool: (params: Record<string, any>) => resolveModelProviderId(params.model),
198199
},
199200
},
200201
inputs: {
@@ -253,8 +254,8 @@ export const RouterV2Block: BlockConfig = {
253254
type: 'combobox',
254255
placeholder: 'Type or select a model...',
255256
required: true,
256-
defaultValue: 'claude-sonnet-5-5',
257-
options: getModelOptions,
257+
defaultValue: DEFAULT_BLOCK_MODEL,
258+
options: getModelOptionsWithAuto,
258259
},
259260
...getProviderCredentialSubBlocks({ bedrockSavedCredential: true }),
260261
getModelFallbackSubBlock(),
@@ -269,7 +270,7 @@ export const RouterV2Block: BlockConfig = {
269270
'deepseek_reasoner',
270271
],
271272
config: {
272-
tool: (params: Record<string, any>) => getSerializedModelProviderId(params.model),
273+
tool: (params: Record<string, any>) => resolveModelProviderId(params.model),
273274
},
274275
},
275276
inputs: {

0 commit comments

Comments
 (0)