MCPcopy Index your code
hub / github.com/simstudioai/sim / evaluateSubBlockCondition

Function evaluateSubBlockCondition

apps/sim/lib/workflows/subblocks/visibility.ts:175–209  ·  view source on GitHub ↗
(
  condition:
    | SubBlockCondition
    | ((values?: Record<string, unknown>) => SubBlockCondition)
    | undefined,
  values: Record<string, unknown>
)

Source from the content-addressed store, hash-verified

173 * Evaluate a subblock condition against a map of raw values.
174 */
175export function evaluateSubBlockCondition(
176 condition:
177 | SubBlockCondition
178 | ((values?: Record<string, unknown>) => SubBlockCondition)
179 | undefined,
180 values: Record<string, unknown>
181): boolean {
182 if (!condition) return true
183 const actual = typeof condition === 'function' ? condition(values) : condition
184 const fieldValue = values[actual.field]
185 const valueMatch = Array.isArray(actual.value)
186 ? fieldValue != null &&
187 (actual.not
188 ? !actual.value.includes(fieldValue as any)
189 : actual.value.includes(fieldValue as any))
190 : actual.not
191 ? fieldValue !== actual.value
192 : fieldValue === actual.value
193 const andMatch = !actual.and
194 ? true
195 : (() => {
196 const andFieldValue = values[actual.and!.field]
197 const andValueMatch = Array.isArray(actual.and!.value)
198 ? andFieldValue != null &&
199 (actual.and!.not
200 ? !actual.and!.value.includes(andFieldValue as any)
201 : actual.and!.value.includes(andFieldValue as any))
202 : actual.and!.not
203 ? andFieldValue !== actual.and!.value
204 : andFieldValue === actual.and!.value
205 return andValueMatch
206 })()
207
208 return valueMatch && andMatch
209}
210
211/**
212 * Check if a value is considered set for advanced visibility/selection.

Callers 15

resolveSubBlockForParamFunction · 0.90
getSubBlocksForToolInputFunction · 0.90
isSubBlockVisibleFunction · 0.90
isVisibleToolParameterFunction · 0.90
visibility.test.tsFile · 0.90
emitAnchoredDependentsFunction · 0.90
isSubBlockRequiredFunction · 0.90
collectClearedDependentsFunction · 0.90
shouldSerializeSubBlockFunction · 0.90

Calls 1

conditionFunction · 0.85

Tested by

no test coverage detected