1+ import {
2+ extractFieldsFromSchema ,
3+ parseResponseFormatSafely ,
4+ } from '@/lib/core/utils/response-format'
15import { normalizeInputFormatValue } from '@/lib/workflows/input-format'
26import { isTriggerBehavior , normalizeName } from '@/executor/constants'
37import type { ExecutionContext } from '@/executor/types'
@@ -43,23 +47,53 @@ function getInputFormatFields(block: SerializedBlock): OutputSchema {
4347 const schema : OutputSchema = { }
4448 for ( const field of inputFormat ) {
4549 if ( ! field . name ) continue
46- schema [ field . name ] = {
47- type : ( field . type || 'any' ) as 'string' | 'number' | 'boolean' | 'object' | 'array' | 'any' ,
48- }
50+ schema [ field . name ] = { type : field . type || 'any' }
4951 }
5052
5153 return schema
5254}
5355
56+ function getEvaluatorMetricsSchema ( block : SerializedBlock ) : OutputSchema | undefined {
57+ if ( block . metadata ?. id !== 'evaluator' ) return undefined
58+
59+ const metrics = block . config ?. params ?. metrics
60+ if ( ! Array . isArray ( metrics ) || metrics . length === 0 ) return undefined
61+
62+ const validMetrics = metrics . filter (
63+ ( m : { name ?: string } ) => m ?. name && typeof m . name === 'string'
64+ )
65+ if ( validMetrics . length === 0 ) return undefined
66+
67+ const schema : OutputSchema = { ...( block . outputs as OutputSchema ) }
68+ for ( const metric of validMetrics ) {
69+ schema [ metric . name . toLowerCase ( ) ] = { type : 'number' }
70+ }
71+ return schema
72+ }
73+
74+ function getResponseFormatSchema ( block : SerializedBlock ) : OutputSchema | undefined {
75+ const responseFormatValue = block . config ?. params ?. responseFormat
76+ if ( ! responseFormatValue ) return undefined
77+
78+ const parsed = parseResponseFormatSafely ( responseFormatValue , block . id )
79+ if ( ! parsed ) return undefined
80+
81+ const fields = extractFieldsFromSchema ( parsed )
82+ if ( fields . length === 0 ) return undefined
83+
84+ const schema : OutputSchema = { }
85+ for ( const field of fields ) {
86+ schema [ field . name ] = { type : field . type || 'any' }
87+ }
88+ return schema
89+ }
90+
5491export function getBlockSchema (
5592 block : SerializedBlock ,
5693 toolConfig ?: ToolConfig
5794) : OutputSchema | undefined {
5895 const blockType = block . metadata ?. id
5996
60- // For blocks that expose inputFormat as outputs, always merge them
61- // This includes both triggers (start_trigger, generic_webhook) and
62- // non-triggers (starter, human_in_the_loop) that have inputFormat
6397 if (
6498 blockType &&
6599 BLOCKS_WITH_INPUT_FORMAT_OUTPUTS . includes (
@@ -74,6 +108,16 @@ export function getBlockSchema(
74108 }
75109 }
76110
111+ const evaluatorSchema = getEvaluatorMetricsSchema ( block )
112+ if ( evaluatorSchema ) {
113+ return evaluatorSchema
114+ }
115+
116+ const responseFormatSchema = getResponseFormatSchema ( block )
117+ if ( responseFormatSchema ) {
118+ return responseFormatSchema
119+ }
120+
77121 const isTrigger = isTriggerBehavior ( block )
78122
79123 if ( isTrigger && block . outputs && Object . keys ( block . outputs ) . length > 0 ) {
0 commit comments