mirror of
https://github.com/simstudioai/sim.git
synced 2026-04-28 03:00:29 -04:00
* improvement(code-quality): centralize regex checks, normalization * simplify resolution * fix(copilot): don't allow duplicate name blocks * centralize uuid check
25 lines
791 B
TypeScript
25 lines
791 B
TypeScript
import { normalizeName } from '@/executor/constants'
|
|
import type { ExecutionContext } from '@/executor/types'
|
|
|
|
export interface BlockDataCollection {
|
|
blockData: Record<string, any>
|
|
blockNameMapping: Record<string, string>
|
|
}
|
|
|
|
export function collectBlockData(ctx: ExecutionContext): BlockDataCollection {
|
|
const blockData: Record<string, any> = {}
|
|
const blockNameMapping: Record<string, string> = {}
|
|
|
|
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?.metadata?.name) {
|
|
blockNameMapping[normalizeName(workflowBlock.metadata.name)] = id
|
|
}
|
|
}
|
|
}
|
|
|
|
return { blockData, blockNameMapping }
|
|
}
|