( workflowId: string, userId: string | undefined, tag: string, kind: 'workflow' | 'current_workflow' = 'workflow', currentWorkspaceId?: string, _chatId?: string )
| 355 | } |
| 356 | |
| 357 | async function processWorkflowFromDb( |
| 358 | workflowId: string, |
| 359 | userId: string | undefined, |
| 360 | tag: string, |
| 361 | kind: 'workflow' | 'current_workflow' = 'workflow', |
| 362 | currentWorkspaceId?: string, |
| 363 | _chatId?: string |
| 364 | ): Promise<AgentContext | null> { |
| 365 | try { |
| 366 | let workflowRecord: Awaited<ReturnType<typeof getActiveWorkflowRecord>> = null |
| 367 | |
| 368 | if (userId) { |
| 369 | const authorization = await authorizeWorkflowByWorkspacePermission({ |
| 370 | workflowId, |
| 371 | userId, |
| 372 | action: 'read', |
| 373 | }) |
| 374 | if (!authorization.allowed) { |
| 375 | return null |
| 376 | } |
| 377 | if (currentWorkspaceId && authorization.workflow?.workspaceId !== currentWorkspaceId) { |
| 378 | return null |
| 379 | } |
| 380 | workflowRecord = authorization.workflow ?? null |
| 381 | } |
| 382 | |
| 383 | if (!workflowRecord) { |
| 384 | workflowRecord = await getActiveWorkflowRecord(workflowId) |
| 385 | } |
| 386 | if (!workflowRecord) return null |
| 387 | |
| 388 | // Emit a VFS-path pointer instead of the full (potentially huge) workflow |
| 389 | // state/meta. `current_workflow` points at the live state; a plain |
| 390 | // `workflow` mention points at the lighter metadata file. |
| 391 | const folderPath = await resolveWorkflowFolderPath( |
| 392 | workflowRecord.workspaceId ?? currentWorkspaceId, |
| 393 | workflowRecord.folderId |
| 394 | ) |
| 395 | const dir = canonicalWorkflowVfsDir({ name: workflowRecord.name, folderPath }) |
| 396 | const path = kind === 'current_workflow' ? `${dir}/state.json` : `${dir}/meta.json` |
| 397 | return { type: kind, tag, content: '', path } |
| 398 | } catch (error) { |
| 399 | logger.error('Error processing workflow context', { workflowId, error }) |
| 400 | return null |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | async function processPastChat(chatId: string, tagOverride?: string): Promise<AgentContext | null> { |
| 405 | try { |
no test coverage detected