Skip to content

Commit a98463a

Browse files
authored
fix(copilot): handle negated operation conditions in block config extraction (#3282)
* fix(copilot): handle negated operation conditions in block config extraction * fix(copilot): simplify condition evaluation to single matchesOperation call
1 parent 765a481 commit a98463a

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

apps/sim/lib/copilot/tools/server/blocks/get-block-config.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,13 @@ interface OutputFieldSchema {
135135
function matchesOperation(condition: any, operation: string): boolean {
136136
if (!condition) return false
137137

138-
const cond = typeof condition === 'function' ? condition() : condition
138+
const cond = typeof condition === 'function' ? condition({ operation }) : condition
139139
if (!cond) return false
140140

141-
if (cond.field === 'operation' && !cond.not) {
141+
if (cond.field === 'operation') {
142142
const values = Array.isArray(cond.value) ? cond.value : [cond.value]
143-
return values.includes(operation)
143+
const included = values.includes(operation)
144+
return cond.not ? !included : included
144145
}
145146

146147
return false
@@ -173,18 +174,10 @@ function extractInputsFromSubBlocks(
173174
// 1. Have no condition (common parameters)
174175
// 2. Have a condition matching the operation
175176
if (operation) {
176-
const condition = typeof sb.condition === 'function' ? sb.condition() : sb.condition
177-
if (condition) {
178-
if (condition.field === 'operation' && !condition.not) {
179-
// This is an operation-specific field
180-
const values = Array.isArray(condition.value) ? condition.value : [condition.value]
181-
if (!values.includes(operation)) {
182-
continue // Skip if doesn't match our operation
183-
}
184-
} else if (!matchesOperation(condition, operation)) {
185-
// Other condition that doesn't match
186-
continue
187-
}
177+
const condition =
178+
typeof sb.condition === 'function' ? sb.condition({ operation }) : sb.condition
179+
if (condition && !matchesOperation(condition, operation)) {
180+
continue
188181
}
189182
}
190183

0 commit comments

Comments
 (0)