11import { z } from 'zod'
2+ import { normalizeInputFormatValue } from '@/lib/workflows/input-format-utils'
3+ import { isValidStartBlockType } from '@/lib/workflows/triggers/trigger-utils'
24import type { InputFormatField } from '@/lib/workflows/types'
35
46/**
@@ -197,18 +199,6 @@ export function generateToolDefinition(
197199 }
198200}
199201
200- /**
201- * Valid start block types that can have input format
202- */
203- const VALID_START_BLOCK_TYPES = [
204- 'starter' ,
205- 'start' ,
206- 'start_trigger' ,
207- 'api' ,
208- 'api_trigger' ,
209- 'input_trigger' ,
210- ]
211-
212202/**
213203 * Extract input format from a workflow's blocks.
214204 * Looks for any valid start block and extracts its inputFormat configuration.
@@ -223,23 +213,18 @@ export function extractInputFormatFromBlocks(
223213 const blockObj = block as Record < string , unknown >
224214 const blockType = blockObj . type as string
225215
226- if ( VALID_START_BLOCK_TYPES . includes ( blockType ) ) {
227- // Try to get inputFormat from subBlocks
228- const subBlocks = blockObj . subBlocks as Record < string , unknown > | undefined
229- if ( subBlocks ?. inputFormat ) {
230- const inputFormatSubBlock = subBlocks . inputFormat as Record < string , unknown >
231- const value = inputFormatSubBlock . value
232- if ( Array . isArray ( value ) ) {
233- return value as InputFormatField [ ]
234- }
235- }
216+ if ( isValidStartBlockType ( blockType ) ) {
217+ // Try to get inputFormat from subBlocks.inputFormat.value
218+ const subBlocks = blockObj . subBlocks as Record < string , { value ?: unknown } > | undefined
219+ const subBlockValue = subBlocks ?. inputFormat ?. value
236220
237221 // Try legacy config.params.inputFormat
238222 const config = blockObj . config as Record < string , unknown > | undefined
239223 const params = config ?. params as Record < string , unknown > | undefined
240- if ( params ?. inputFormat && Array . isArray ( params . inputFormat ) ) {
241- return params . inputFormat as InputFormatField [ ]
242- }
224+ const paramsValue = params ?. inputFormat
225+
226+ const normalized = normalizeInputFormatValue ( subBlockValue ?? paramsValue )
227+ return normalized . length > 0 ? normalized : null
243228 }
244229 }
245230
0 commit comments