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

Function onBlockCompleteCallback

apps/sim/lib/workflows/streaming/streaming.ts:443–534  ·  view source on GitHub ↗
(blockId: string, output: unknown)

Source from the content-addressed store, hash-verified

441 const base64MaxBytes = streamConfig.base64MaxBytes
442
443 const onBlockCompleteCallback = async (blockId: string, output: unknown) => {
444 state.completedBlockIds.add(blockId)
445
446 if (!streamConfig.selectedOutputs?.length) {
447 return
448 }
449
450 if (state.streamedChunks.has(blockId)) {
451 return
452 }
453
454 const matchingOutputs = getSelectedOutputDescriptors(streamConfig.selectedOutputs).filter(
455 (descriptor) => descriptor.blockId === blockId
456 )
457
458 for (const descriptor of matchingOutputs) {
459 if (state.selectedOutputError) {
460 break
461 }
462 try {
463 const remainingBytes = getRemainingSelectedOutputBytes(state.selectedOutputBytes)
464 const extractionContext = {
465 requestId,
466 workspaceId: options.workspaceId,
467 workflowId: options.workflowId,
468 executionId,
469 largeValueExecutionIds: options.largeValueExecutionIds,
470 largeValueKeys: options.largeValueKeys,
471 fileKeys: options.fileKeys,
472 allowLargeValueWorkflowScope: options.allowLargeValueWorkflowScope,
473 userId: options.userId,
474 base64MaxBytes: Math.min(
475 base64MaxBytes ?? MAX_INLINE_MATERIALIZATION_BYTES,
476 getBase64DecodedByteBudget(remainingBytes)
477 ),
478 }
479 const materializationContext = buildMaterializationContext(extractionContext)
480 const outputValue = await extractOutputValue(output, descriptor.path, extractionContext)
481
482 if (outputValue !== undefined) {
483 const materializedOutput = await materializeInlineExecutionValue(
484 outputValue,
485 materializationContext,
486 { maxBytes: remainingBytes }
487 )
488 const shouldHydrateOutput = includeFileBase64
489 const hydratedOutput = shouldHydrateOutput
490 ? await hydrateUserFilesWithBase64(materializedOutput, {
491 requestId,
492 ...materializationContext,
493 maxBytes: Math.min(
494 base64MaxBytes ?? MAX_INLINE_MATERIALIZATION_BYTES,
495 getBase64DecodedByteBudget(remainingBytes)
496 ),
497 preserveLargeValueMetadata: true,
498 })
499 : materializedOutput
500 await materializeInlineExecutionValue(hydratedOutput, materializationContext, {

Callers 1

onBlockCompletedFunction · 0.85

Calls 14

getInlineJsonByteLengthFunction · 0.90
encodeSSEFunction · 0.90
extractOutputValueFunction · 0.85
sendChunkFunction · 0.85
warnMethod · 0.65

Tested by

no test coverage detected