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

Function processWorkflowBlockFromDb

apps/sim/lib/copilot/chat/process-contents.ts:519–566  ·  view source on GitHub ↗
(
  workflowId: string,
  userId: string | undefined,
  blockId: string,
  label?: string,
  currentWorkspaceId?: string
)

Source from the content-addressed store, hash-verified

517}
518
519async function processWorkflowBlockFromDb(
520 workflowId: string,
521 userId: string | undefined,
522 blockId: string,
523 label?: string,
524 currentWorkspaceId?: string
525): Promise<AgentContext | null> {
526 try {
527 let workflowRecord: Awaited<ReturnType<typeof getActiveWorkflowRecord>> = null
528 if (userId) {
529 const authorization = await authorizeWorkflowByWorkspacePermission({
530 workflowId,
531 userId,
532 action: 'read',
533 })
534 if (!authorization.allowed) {
535 return null
536 }
537 if (currentWorkspaceId && authorization.workflow?.workspaceId !== currentWorkspaceId) {
538 return null
539 }
540 workflowRecord = authorization.workflow ?? null
541 }
542
543 if (!workflowRecord) {
544 workflowRecord = await getActiveWorkflowRecord(workflowId)
545 }
546 if (!workflowRecord) return null
547
548 const folderPath = await resolveWorkflowFolderPath(
549 workflowRecord.workspaceId ?? currentWorkspaceId,
550 workflowRecord.folderId
551 )
552 const dir = canonicalWorkflowVfsDir({ name: workflowRecord.name, folderPath })
553 const tag = label ? `@${label} in Workflow` : `@${blockId} in Workflow`
554 // Point at the workflow state; the block id tells the model which node to
555 // look up inside state.json without inlining the full block definition.
556 return {
557 type: 'workflow_block',
558 tag,
559 content: `Block id: ${blockId}`,
560 path: `${dir}/state.json`,
561 }
562 } catch (error) {
563 logger.error('Error processing workflow_block context', { workflowId, blockId, error })
564 return null
565 }
566}
567
568async function processExecutionLogFromDb(
569 executionId: string,

Callers 1

processContextsServerFunction · 0.85

Calls 5

getActiveWorkflowRecordFunction · 0.90
canonicalWorkflowVfsDirFunction · 0.90
errorMethod · 0.80

Tested by

no test coverage detected