Skip to content

Commit 20b230d

Browse files
improvement(schema): centralize derivation of block schemas (#3175)
* improvement(schema): centralize derivation of block schemas * address bugbot comments * remove unused code * address greptile comments * merge conflict resolution * fix * update tests * address greptile comments * make evaluator metrics only * return base and metrics for evaluator
1 parent be3cdcf commit 20b230d

File tree

16 files changed

+484
-783
lines changed

16 files changed

+484
-783
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/chat/components/output-select/output-select.tsx

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@ import type React from 'react'
44
import { useMemo } from 'react'
55
import { RepeatIcon, SplitIcon } from 'lucide-react'
66
import { Combobox, type ComboboxOptionGroup } from '@/components/emcn'
7-
import {
8-
extractFieldsFromSchema,
9-
parseResponseFormatSafely,
10-
} from '@/lib/core/utils/response-format'
11-
import { getToolOutputs } from '@/lib/workflows/blocks/block-outputs'
7+
import { getEffectiveBlockOutputs } from '@/lib/workflows/blocks/block-outputs'
8+
import { hasTriggerCapability } from '@/lib/workflows/triggers/trigger-utils'
129
import { getBlock } from '@/blocks'
1310
import { useWorkflowDiffStore } from '@/stores/workflow-diff/store'
1411
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
@@ -124,42 +121,27 @@ export function OutputSelect({
124121
: `block-${block.id}`
125122

126123
const blockConfig = getBlock(block.type)
127-
const responseFormatValue =
128-
shouldUseBaseline && baselineWorkflow
129-
? baselineWorkflow.blocks?.[block.id]?.subBlocks?.responseFormat?.value
130-
: subBlockValues?.[block.id]?.responseFormat
131-
const responseFormat = parseResponseFormatSafely(responseFormatValue, block.id)
124+
const isTriggerCapable = blockConfig ? hasTriggerCapability(blockConfig) : false
125+
const effectiveTriggerMode = Boolean(block.triggerMode && isTriggerCapable)
132126

133127
let outputsToProcess: Record<string, unknown> = {}
134-
135-
if (responseFormat) {
136-
const schemaFields = extractFieldsFromSchema(responseFormat)
137-
if (schemaFields.length > 0) {
138-
schemaFields.forEach((field) => {
139-
outputsToProcess[field.name] = { type: field.type }
140-
})
141-
} else {
142-
outputsToProcess = blockConfig?.outputs || {}
143-
}
144-
} else {
145-
// Build subBlocks object for tool selector
146-
const rawSubBlockValues =
147-
shouldUseBaseline && baselineWorkflow
148-
? baselineWorkflow.blocks?.[block.id]?.subBlocks
149-
: subBlockValues?.[block.id]
150-
const subBlocks: Record<string, { value: unknown }> = {}
151-
if (rawSubBlockValues && typeof rawSubBlockValues === 'object') {
152-
for (const [key, val] of Object.entries(rawSubBlockValues)) {
153-
// Handle both { value: ... } and raw value formats
154-
subBlocks[key] = val && typeof val === 'object' && 'value' in val ? val : { value: val }
155-
}
128+
const rawSubBlockValues =
129+
shouldUseBaseline && baselineWorkflow
130+
? baselineWorkflow.blocks?.[block.id]?.subBlocks
131+
: subBlockValues?.[block.id]
132+
const subBlocks: Record<string, { value: unknown }> = {}
133+
if (rawSubBlockValues && typeof rawSubBlockValues === 'object') {
134+
for (const [key, val] of Object.entries(rawSubBlockValues)) {
135+
// Handle both { value: ... } and raw value formats
136+
subBlocks[key] = val && typeof val === 'object' && 'value' in val ? val : { value: val }
156137
}
157-
158-
const toolOutputs = blockConfig ? getToolOutputs(blockConfig, subBlocks) : {}
159-
outputsToProcess =
160-
Object.keys(toolOutputs).length > 0 ? toolOutputs : blockConfig?.outputs || {}
161138
}
162139

140+
outputsToProcess = getEffectiveBlockOutputs(block.type, subBlocks, {
141+
triggerMode: effectiveTriggerMode,
142+
preferToolOutputs: !effectiveTriggerMode,
143+
}) as Record<string, unknown>
144+
163145
if (Object.keys(outputsToProcess).length === 0) return
164146

165147
const addOutput = (path: string, outputObj: unknown, prefix = '') => {

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/connection-blocks/connection-blocks.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ function ConnectionItem({
6161
blockId: connection.id,
6262
blockType: connection.type,
6363
mergedSubBlocks,
64-
responseFormat: connection.responseFormat,
65-
operation: connection.operation,
6664
triggerMode: sourceBlock?.triggerMode,
6765
})
6866
const hasFields = fields.length > 0

0 commit comments

Comments
 (0)