Skip to content

Commit 603b547

Browse files
fix(copilot): null check simplified (#1431)
1 parent ab8d822 commit 603b547

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

apps/sim/lib/copilot/tools/server/blocks/get-blocks-metadata-tool.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export const getBlocksMetadataServerTool: BaseServerTool<
230230
} catch {}
231231

232232
if (metadata) {
233-
result[blockId] = pruneNullishDeep(metadata) as CopilotBlockMetadata
233+
result[blockId] = removeNullish(metadata) as CopilotBlockMetadata
234234
}
235235
}
236236

@@ -370,23 +370,18 @@ function resolveSubblockOptions(
370370
}
371371
}
372372

373-
function pruneNullishDeep<T>(value: T): T {
374-
if (value === null || value === undefined) return value
375-
if (Array.isArray(value)) {
376-
const prunedArray = (value as unknown[])
377-
.map((v) => pruneNullishDeep(v))
378-
.filter((v) => v !== undefined && v !== null)
379-
return prunedArray as unknown as T
380-
}
381-
if (typeof value === 'object') {
382-
const output: Record<string, any> = {}
383-
for (const [k, v] of Object.entries(value as Record<string, any>)) {
384-
const pruned = pruneNullishDeep(v)
385-
if (pruned !== undefined && pruned !== null) output[k] = pruned
373+
function removeNullish(obj: any): any {
374+
if (!obj || typeof obj !== 'object') return obj
375+
376+
const cleaned: any = Array.isArray(obj) ? [] : {}
377+
378+
for (const [key, value] of Object.entries(obj)) {
379+
if (value !== null && value !== undefined) {
380+
cleaned[key] = value
386381
}
387-
return output as unknown as T
388382
}
389-
return value
383+
384+
return cleaned
390385
}
391386

392387
function normalizeCondition(condition: any): any | undefined {

0 commit comments

Comments
 (0)