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

Function filterOutputsByCondition

apps/sim/lib/workflows/blocks/block-outputs.ts:103–133  ·  view source on GitHub ↗

* Filters outputs based on their conditions and hiddenFromDisplay flag. * Returns a new OutputDefinition with only the outputs that should be shown.

(
  outputs: OutputDefinition,
  subBlocks: Record<string, SubBlockWithValue> | undefined,
  includeHidden = false
)

Source from the content-addressed store, hash-verified

101 * Returns a new OutputDefinition with only the outputs that should be shown.
102 */
103function filterOutputsByCondition(
104 outputs: OutputDefinition,
105 subBlocks: Record<string, SubBlockWithValue> | undefined,
106 includeHidden = false
107): OutputDefinition {
108 const filtered: OutputDefinition = {}
109
110 for (const [key, value] of Object.entries(outputs)) {
111 if (!includeHidden && isHiddenFromDisplay(value)) continue
112
113 if (!value || typeof value !== 'object' || !('condition' in value)) {
114 filtered[key] = value
115 continue
116 }
117
118 const condition = value.condition as OutputCondition | undefined
119 const passes = !condition || evaluateOutputCondition(condition, subBlocks)
120
121 if (passes) {
122 if (includeHidden) {
123 const { condition: _, ...rest } = value
124 filtered[key] = rest
125 } else {
126 const { condition: _, hiddenFromDisplay: __, ...rest } = value
127 filtered[key] = rest
128 }
129 }
130 }
131
132 return filtered
133}
134
135const CHAT_OUTPUTS: OutputDefinition = {
136 input: { type: 'string', description: 'User message' },

Callers 1

getBlockOutputsFunction · 0.85

Calls 2

isHiddenFromDisplayFunction · 0.90
evaluateOutputConditionFunction · 0.85

Tested by

no test coverage detected