* 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 )
| 101 | * Returns a new OutputDefinition with only the outputs that should be shown. |
| 102 | */ |
| 103 | function 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 | |
| 135 | const CHAT_OUTPUTS: OutputDefinition = { |
| 136 | input: { type: 'string', description: 'User message' }, |
no test coverage detected