Skip to content

Commit 6f3aa73

Browse files
committed
fix(workflows): offer no child fields for arrays of typed elements
The connection panel listed an items child for an array whose elements are a typed node without properties, such as an MCP array of strings or of untyped elements, offering an invalid reference.
1 parent 49f370c commit 6f3aa73

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @vitest-environment node
3+
*/
4+
import { describe, expect, it } from 'vitest'
5+
import { createFieldFromOutput } from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-block-output-fields'
6+
7+
describe('createFieldFromOutput', () => {
8+
it.each([
9+
['untyped elements', { type: 'any' }],
10+
['primitive elements', { type: 'string' }],
11+
])('offers no child fields for an array of %s', (_, items) => {
12+
const field = createFieldFromOutput('rows', { type: 'array', items })
13+
expect(field.children).toBeUndefined()
14+
})
15+
16+
it('offers the declared fields of object elements', () => {
17+
const field = createFieldFromOutput('rows', {
18+
type: 'array',
19+
items: { type: 'object', properties: { id: { type: 'string' } } },
20+
})
21+
expect(field.children?.map((child) => child.name)).toEqual(['id'])
22+
})
23+
})

‎apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-block-output-fields.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ const extractChildFields = (prop: any): SchemaField[] | undefined => {
3535
return extractNestedFields(prop.items.properties)
3636
}
3737

38+
/** Typed elements without `properties` (strings, `any`) have no fields to reference. */
39+
if (isObject(prop.items) && typeof prop.items.type === 'string') {
40+
return undefined
41+
}
42+
3843
if (!('type' in prop)) {
3944
return extractNestedFields(prop)
4045
}
@@ -71,7 +76,7 @@ const extractNestedFields = (properties: Record<string, any>): SchemaField[] =>
7176
/**
7277
* Creates a schema field from an output definition
7378
*/
74-
const createFieldFromOutput = (name: string, output: any): SchemaField => {
79+
export const createFieldFromOutput = (name: string, output: any): SchemaField => {
7580
const hasExplicitType = isObject(output) && typeof output.type === 'string'
7681
const type = hasExplicitType ? output.type : isObject(output) ? 'object' : 'string'
7782

0 commit comments

Comments
 (0)