mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-23 22:08:09 -05:00
* fix(resolver): consolidate code to resolve references * fix edge cases * use already formatted error * fix multi index * fix backwards compat reachability * handle backwards compatibility accurately * use shared constant correctly
44 lines
1.5 KiB
TypeScript
44 lines
1.5 KiB
TypeScript
import { getBlockOutputs } from '@/lib/workflows/blocks/block-outputs'
|
|
import { normalizeName } from '@/executor/constants'
|
|
import type { ExecutionContext } from '@/executor/types'
|
|
import type { OutputSchema } from '@/executor/utils/block-reference'
|
|
|
|
export interface BlockDataCollection {
|
|
blockData: Record<string, unknown>
|
|
blockNameMapping: Record<string, string>
|
|
blockOutputSchemas: Record<string, OutputSchema>
|
|
}
|
|
|
|
export function collectBlockData(ctx: ExecutionContext): BlockDataCollection {
|
|
const blockData: Record<string, unknown> = {}
|
|
const blockNameMapping: Record<string, string> = {}
|
|
const blockOutputSchemas: Record<string, OutputSchema> = {}
|
|
|
|
for (const [id, state] of ctx.blockStates.entries()) {
|
|
if (state.output !== undefined) {
|
|
blockData[id] = state.output
|
|
}
|
|
|
|
const workflowBlock = ctx.workflow?.blocks?.find((b) => b.id === id)
|
|
if (!workflowBlock) continue
|
|
|
|
if (workflowBlock.metadata?.name) {
|
|
blockNameMapping[normalizeName(workflowBlock.metadata.name)] = id
|
|
}
|
|
|
|
const blockType = workflowBlock.metadata?.id
|
|
if (blockType) {
|
|
const params = workflowBlock.config?.params as Record<string, unknown> | undefined
|
|
const subBlocks = params
|
|
? Object.fromEntries(Object.entries(params).map(([k, v]) => [k, { value: v }]))
|
|
: undefined
|
|
const schema = getBlockOutputs(blockType, subBlocks)
|
|
if (schema && Object.keys(schema).length > 0) {
|
|
blockOutputSchemas[id] = schema
|
|
}
|
|
}
|
|
}
|
|
|
|
return { blockData, blockNameMapping, blockOutputSchemas }
|
|
}
|