MCPcopy Index your code
hub / github.com/simstudioai/sim / serializeBlock

Method serializeBlock

apps/sim/serializer/index.ts:195–310  ·  view source on GitHub ↗
(
    block: BlockState,
    options: {
      validateRequired: boolean
      allBlocks: Record<string, BlockState>
    }
  )

Source from the content-addressed store, hash-verified

193 }
194
195 private serializeBlock(
196 block: BlockState,
197 options: {
198 validateRequired: boolean
199 allBlocks: Record<string, BlockState>
200 }
201 ): SerializedBlock {
202 // Special handling for subflow blocks (loops, parallels, etc.)
203 if (block.type === 'loop' || block.type === 'parallel') {
204 return {
205 id: block.id,
206 position: block.position,
207 config: {
208 tool: '', // Loop blocks don't have tools
209 params: (block.data || {}) as Record<string, unknown>, // Preserve the block data (parallelType, count, etc.)
210 },
211 inputs: {},
212 outputs: block.outputs,
213 metadata: {
214 id: block.type,
215 name: block.name,
216 description: block.type === 'loop' ? 'Loop container' : 'Parallel container',
217 category: 'subflow',
218 color: block.type === 'loop' ? '#3b82f6' : '#8b5cf6',
219 },
220 enabled: block.enabled,
221 }
222 }
223
224 const blockConfig = getBlock(block.type)
225 if (!blockConfig) {
226 throw new Error(`Invalid block type: ${block.type}`)
227 }
228
229 // Extract parameters from UI state
230 const params = extractBlockParams(block)
231
232 const isTriggerCategory = blockConfig.category === 'triggers'
233 if (block.triggerMode === true || isTriggerCategory) {
234 params.triggerMode = true
235 }
236 if (block.advancedMode === true) {
237 params.advancedMode = true
238 }
239
240 // Validate required fields that only users can provide (before execution starts)
241 if (options.validateRequired) {
242 const { missingRequiredFields } = collectBlockFieldIssues(block, blockConfig, params)
243 if (missingRequiredFields.length > 0) {
244 const blockName = block.name || blockConfig.name || 'Block'
245 throw new Error(
246 `${blockName} is missing required fields: ${missingRequiredFields.join(', ')}`
247 )
248 }
249 }
250
251 let toolId = ''
252

Callers 1

serializeWorkflowMethod · 0.95

Calls 7

getBlockFunction · 0.90
extractBlockParamsFunction · 0.85
collectBlockFieldIssuesFunction · 0.85
selectToolIdFunction · 0.85
joinMethod · 0.80
parseMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected