MCPcopy
hub / github.com/simstudioai/sim / appendWorkflowEntry

Function appendWorkflowEntry

apps/sim/stores/terminal/console/store.ts:205–239  ·  view source on GitHub ↗
(
  state: ConsoleStore,
  workflowId: string,
  newEntry: ConsoleEntry,
  trimmedEntries: ConsoleEntry[]
)

Source from the content-addressed store, hash-verified

203}
204
205function appendWorkflowEntry(
206 state: ConsoleStore,
207 workflowId: string,
208 newEntry: ConsoleEntry,
209 trimmedEntries: ConsoleEntry[]
210): Pick<ConsoleStore, 'workflowEntries' | 'entryIdsByBlockExecution' | 'entryLocationById'> {
211 const workflowEntries = cloneWorkflowEntries(state.workflowEntries)
212 const previousEntries = workflowEntries[workflowId] ?? EMPTY_CONSOLE_ENTRIES
213 workflowEntries[workflowId] = trimmedEntries
214
215 const entryLocationById = { ...state.entryLocationById }
216 const entryIdsByBlockExecution = { ...state.entryIdsByBlockExecution }
217
218 const survivingIds = new Set(trimmedEntries.map((e) => e.id))
219 const droppedEntries = previousEntries.filter((e) => !survivingIds.has(e.id))
220 if (droppedEntries.length > 0) {
221 removeWorkflowIndexes(workflowId, droppedEntries, entryIdsByBlockExecution, entryLocationById)
222 }
223
224 trimmedEntries.forEach((entry, index) => {
225 entryLocationById[entry.id] = { workflowId, index }
226 })
227
228 const blockExecutionKey = getBlockExecutionKey(newEntry.blockId, newEntry.executionId)
229 const existingIds = entryIdsByBlockExecution[blockExecutionKey]
230 if (existingIds) {
231 if (!existingIds.includes(newEntry.id)) {
232 entryIdsByBlockExecution[blockExecutionKey] = [...existingIds, newEntry.id]
233 }
234 } else {
235 entryIdsByBlockExecution[blockExecutionKey] = [newEntry.id]
236 }
237
238 return { workflowEntries, entryIdsByBlockExecution, entryLocationById }
239}
240
241interface NotifyBlockErrorParams {
242 error: unknown

Callers 1

store.tsFile · 0.85

Calls 3

cloneWorkflowEntriesFunction · 0.85
removeWorkflowIndexesFunction · 0.85
getBlockExecutionKeyFunction · 0.85

Tested by

no test coverage detected