( workflowId: string, userId: string | undefined, blockId: string, label?: string, currentWorkspaceId?: string )
| 517 | } |
| 518 | |
| 519 | async 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 | |
| 568 | async function processExecutionLogFromDb( |
| 569 | executionId: string, |
no test coverage detected