Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import { useAccessibleReferencePrefixes } from '@/app/workspace/[workspaceId]/w/
import type { SubBlockConfig } from '@/blocks/types'
import { useDebounce } from '@/hooks/use-debounce'
import { usePermissionConfig } from '@/hooks/use-permission-config'
import { DEFAULT_BLOCK_MODEL } from '@/providers/default-model'
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
import { useSubBlockStore } from '@/stores/workflows/subblock/store'

/**
* Constants for ComboBox component behavior
*/
const DEFAULT_MODEL = 'claude-sonnet-5-5'
const ZOOM_FACTOR_BASE = 0.96
const MIN_ZOOM = 0.1
const MAX_ZOOM = 1
Expand Down Expand Up @@ -308,7 +308,7 @@ export const ComboBox = memo(function ComboBox({

/**
* Determines the default option value to use.
* Priority: explicit defaultValue > DEFAULT_MODEL for model field > first option
* Priority: explicit defaultValue > DEFAULT_BLOCK_MODEL for model field > first option
*/
const defaultOptionValue = useMemo(() => {
if (defaultValue !== undefined) {
Expand All @@ -322,7 +322,7 @@ export const ComboBox = memo(function ComboBox({

if (subBlockId === 'model') {
const defaultModelOption = evaluatedOptions.find(
(opt) => getOptionValue(opt) === DEFAULT_MODEL
(opt) => getOptionValue(opt) === DEFAULT_BLOCK_MODEL
)
if (defaultModelOption) {
return getOptionValue(defaultModelOption)
Expand Down
10 changes: 5 additions & 5 deletions apps/sim/blocks/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ export function getAgentModelOptions() {
* catalog, and whether each offers Auto (so accepts sim-auto on hosted Sim).
*
* {@link getAgentModelOptions} is deliberately absent: the agent's model field also takes
* bare Ollama names, free-typed ids (Bedrock inference profiles, fine-tunes) and retired
* ids, so validation passes its values through unchanged.
* free-typed ids (Bedrock inference profiles, fine-tunes) and retired ids, so validation
* passes its values through unchanged.
*/
export const MODEL_OPTION_SOURCES: ReadonlyMap<unknown, { auto: boolean }> = new Map([
[getModelOptions, { auto: false }],
Expand Down Expand Up @@ -352,12 +352,12 @@ function getProviderFromStore(model: string): string | null {
}

/**
* Whether an Ollama instance is available. `isOllamaConfigured` reads the
* Whether this browser knows of an Ollama instance. `isOllamaConfigured` reads the
* server-only `OLLAMA_URL` env var, which is always undefined in the browser —
* there the providers store (populated from the server's model list, which is
* non-empty only when Ollama is configured) is the signal.
*/
function isOllamaAvailable(): boolean {
function hasOllamaInstance(): boolean {
if (isOllamaConfigured) return true
return useProvidersStore.getState().providers.ollama.models.length > 0
}
Expand Down Expand Up @@ -417,7 +417,7 @@ export function shouldRequireApiKeyForModel(model: string): boolean {
return false
if (storeProvider) return true

if (isOllamaAvailable()) {
if (hasOllamaInstance()) {
if (normalizedModel.includes('/')) return true
if (normalizedModel in getBaseModelProviders()) return true
return false
Expand Down
15 changes: 8 additions & 7 deletions apps/sim/lib/model-router/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,13 @@ async function callModelRouter(
}

/**
* Resolves the sim-auto pseudo-model to a concrete model for one block
* execution. Like any model check it throws when the workspace's permission group
* denies sim-auto itself or its permission config cannot be loaded. Otherwise it never fails
* the workflow: any error, timeout, non-hosted deployment, or fully unavailable
* pool column falls back to `fallbackModel` (the block's standard default). Callers must supply the same already-projected
* model-facing signals they pass to their provider boundary; this router never rescans them.
* Resolves the sim-auto pseudo-model to a concrete model for one block execution. Like any
* model check it throws when the workspace's permission group denies sim-auto itself or its
* permission config cannot be loaded. Otherwise it never fails the workflow: any error,
* timeout, non-hosted deployment, or fully unavailable pool column falls back to
* `fallbackModel` (the block's standard default). Callers must supply the same
* already-projected model-facing signals they pass to their provider boundary; this router
* never rescans them.
*/
export async function resolveAutoModel(args: {
ctx: ExecutionContext
Expand All @@ -262,7 +263,7 @@ export async function resolveAutoModel(args: {
fallbackModel: string
}): Promise<AutoRoutingResult> {
const { ctx, blockId, signals, fallbackModel } = args
// Before any fallback: a denied sim-auto must not run as whichever pool or default model is allowed.
// Before any fallback: a denied sim-auto must not run as whichever model is allowed.
await validateModelProvider(ctx.userId, ctx.workspaceId ?? undefined, SIM_AUTO_MODEL_ID, ctx)
const fallback: AutoRoutingResult = {
model: fallbackModel,
Expand Down
6 changes: 3 additions & 3 deletions apps/sim/lib/mothership/request/session/run-replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ export async function openRunReplay(params: {
}

/**
* The end a `replay_end` frame reports: its reason, `closed` for a frame this build
* cannot parse (an unknown reason, a missing length), or `null` for any other frame. It is worker-to-Sim control, never a
* stream event, whatever reason it carries.
* The end a `replay_end` frame reports: its reason, `closed` for a frame this build cannot
* parse (an unknown reason, a missing length), or `null` for any other frame. It is
* worker-to-Sim control, never a stream event, whatever reason it carries.
*/
function replayEnd(value: unknown): RunReplayEnd | null {
if (!isRecordLike(value) || value.type !== MothershipStreamV1EventType.run) return null
Expand Down
39 changes: 39 additions & 0 deletions apps/sim/lib/workflows/editing/validation-models.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,42 @@ describe('model ids no provider declares', () => {
expect(errors[0]?.error).toContain('Unknown model id')
})
})

describe('fallback model rows', () => {
function validateFallback(blockType: string, model: string) {
const result = validateInputsForBlock(
blockType,
{ fallbackModels: [{ id: 'row-1', model }] },
`${blockType}-1`
)
return { errors: result.errors, rows: result.validInputs.fallbackModels }
}

it.each(['agent', 'router_v2', 'evaluator'])(
'accepts an installed Ollama model on %s where Ollama is reachable, as the model field does',
(blockType) => {
const { errors, rows } = validateFallback(blockType, 'mistral:latest')
expect(errors).toEqual([])
expect(rows).toEqual([expect.objectContaining({ model: 'mistral:latest' })])
}
)

it('rejects it on hosted Sim with no Ollama', () => {
setEnvFlags({ isHosted: true })
const { errors } = validateFallback('agent', 'mistral:latest')
expect(errors[0]?.error).toContain('unknown model id "mistral:latest"')
})

it('rejects it when the Ollama provider is blacklisted', () => {
envFlagsMockFns.getBlacklistedProvidersFromEnv.mockReturnValue(['ollama'])
const { errors } = validateFallback('agent', 'mistral:latest')
expect(errors[0]?.error).toContain('unknown model id "mistral:latest"')
})

it('still rejects sim-auto and free text', () => {
expect(validateFallback('agent', 'sim-auto').errors[0]?.error).toContain('sim-auto')
expect(validateFallback('agent', 'best available model').errors[0]?.error).toContain(
'unknown model id'
)
})
})
8 changes: 7 additions & 1 deletion apps/sim/lib/workflows/editing/validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,13 @@ describe('validateInputsForBlock', () => {
it('refuses sim-auto, evaluation models, unknown models, missing models, and non-arrays', () => {
expect(validate([{ model: 'sim-auto' }]).valid).toBe(false)
expect(validate([{ model: 'jev-latest' }]).valid).toBe(false)
expect(validate([{ model: 'definitely-not-a-model-9000' }]).valid).toBe(false)
// An unclaimed Ollama-shaped name is a possible local model wherever Ollama is reachable.
setEnvFlags({ isHosted: true })
try {
expect(validate([{ model: 'definitely-not-a-model-9000' }]).valid).toBe(false)
} finally {
setEnvFlags({ isHosted: false })
}
expect(validate([{ apiKey: '{{KEY}}' }]).valid).toBe(false)
expect(validate({ model: 'claude-sonnet-5' }).valid).toBe(false)
})
Expand Down
35 changes: 20 additions & 15 deletions apps/sim/lib/workflows/editing/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ function validateFallbackModelEntry(item: any, index: number): string | null {
if (isEvaluationModel(model)) {
return `${where}: ${model} is an evaluation model and cannot serve as a chat fallback`
}
if (!isKnownModelId(model) && !isCustomModelId(model)) {
if (!isRunnableModelId(model)) {
const suggestions = suggestModelIdsForUnknownModel(model)
const suggestionText =
suggestions.length > 0 ? ` Valid options include: ${suggestions.join(', ')}.` : ''
Expand All @@ -585,6 +585,23 @@ function validateFallbackModelEntry(item: any, index: number): string | null {
return null
}

/**
* Whether Sim can run `model`: a catalogued or namespaced id, or a local Ollama name. An id no
* provider claims runs on Ollama (`getProviderFromModel`'s default), so wherever an Ollama server
* is reachable an Ollama-shaped name may be a locally installed model. The server cannot list
* what is installed, so a mistyped name of that shape fails at execution instead. sim-auto is
* never one: it never reaches a provider as itself.
*/
function isRunnableModelId(model: string): boolean {
if (isKnownModelId(model) || isCustomModelId(model)) return true
return (
!isAutoModel(model) &&
OLLAMA_MODEL_NAME.test(model) &&
findProviderFromModel(model) === null &&
isOllamaAvailable()
)
}

/** A file object as the file-upload editor stores it: at least its name and serve path. */
function isStoredFile(value: unknown): boolean {
return isPlainRecord(value) && Boolean(value.name) && Boolean(value.path)
Expand Down Expand Up @@ -1001,22 +1018,10 @@ export function validateValueForSubBlockType(
}
// sim-auto is valid only where the source offers Auto, which it does on hosted Sim
// only; writes of it anywhere else are rejected as unknown.
const isAuto = isAutoModel(trimmed)
if (isAuto && modelSource.auto && isHostedDeployment) {
if (isAutoModel(trimmed) && modelSource.auto && isHostedDeployment) {
return { valid: true, value: trimmed.toLowerCase() }
}
// An id no provider claims runs on Ollama (`getProviderFromModel`'s default), so
// wherever an Ollama server is reachable an Ollama-shaped name may be a locally
// installed model. The server cannot list what is installed, so a mistyped name of
// that shape fails at execution instead. sim-auto is never one: it never reaches a
// provider as itself.
const isUnknown = !isKnownModelId(trimmed) && !isCustomModelId(trimmed)
const mayBeLocalModel =
!isAuto &&
OLLAMA_MODEL_NAME.test(trimmed) &&
findProviderFromModel(trimmed) === null &&
isOllamaAvailable()
if (trimmed !== '' && isUnknown && !mayBeLocalModel) {
if (trimmed !== '' && !isRunnableModelId(trimmed)) {
const suggestions = suggestModelIdsForUnknownModel(trimmed)
const suggestionText =
suggestions.length > 0 ? ` Valid options include: ${suggestions.join(', ')}.` : ''
Expand Down
Loading