MCPcopy Create free account
hub / github.com/simstudioai/sim / resolveStartCandidates

Function resolveStartCandidates

apps/sim/lib/workflows/triggers/triggers.ts:173–221  ·  view source on GitHub ↗
(
  blocks: Record<string, T> | T[],
  options: ResolveStartOptions
)

Source from the content-addressed store, hash-verified

171}
172
173export function resolveStartCandidates<T extends MinimalBlock>(
174 blocks: Record<string, T> | T[],
175 options: ResolveStartOptions
176): StartBlockCandidate<T>[] {
177 const entries = toEntries(blocks)
178 if (entries.length === 0) return []
179
180 const priorities = options.isChildWorkflow
181 ? CHILD_PRIORITIES
182 : EXECUTION_PRIORITIES[options.execution]
183
184 const candidates: StartBlockCandidate<T>[] = []
185
186 for (const [blockId, block] of entries) {
187 // Skip disabled blocks - they cannot be used as triggers
188 if ('enabled' in block && block.enabled === false) {
189 continue
190 }
191
192 const path = classifyStartBlock(block)
193 if (!path) continue
194
195 if (options.isChildWorkflow) {
196 if (!CHILD_PRIORITIES.includes(path)) {
197 continue
198 }
199 } else if (!supportsExecution(path, options.execution)) {
200 continue
201 }
202
203 if (path === StartBlockPath.LEGACY_STARTER && options.allowLegacyStarter === false) {
204 continue
205 }
206
207 candidates.push({ blockId, block, path })
208 }
209
210 candidates.sort((a, b) => {
211 const order = options.isChildWorkflow ? CHILD_PRIORITIES : priorities
212 const aIdx = order.indexOf(a.path)
213 const bIdx = order.indexOf(b.path)
214 if (aIdx === -1 && bIdx === -1) return 0
215 if (aIdx === -1) return 1
216 if (bIdx === -1) return -1
217 return aIdx - bIdx
218 })
219
220 return candidates
221}
222
223type SubBlockWithValue = { value?: unknown }
224

Callers 7

resolveTriggerRunOptionsFunction · 0.90
getStartBlockInputFormatFunction · 0.90
getInputFormatExampleFunction · 0.90
executeWorkflowFunction · 0.90
useWorkflowExecutionFunction · 0.90
findStartBlockMethod · 0.85

Calls 4

toEntriesFunction · 0.85
classifyStartBlockFunction · 0.85
supportsExecutionFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected