( executionId: string, userId: string | undefined, tag: string, currentWorkspaceId?: string )
| 566 | } |
| 567 | |
| 568 | async function processExecutionLogFromDb( |
| 569 | executionId: string, |
| 570 | userId: string | undefined, |
| 571 | tag: string, |
| 572 | currentWorkspaceId?: string |
| 573 | ): Promise<AgentContext | null> { |
| 574 | try { |
| 575 | const { workflowExecutionLogs, workflow } = await import('@sim/db/schema') |
| 576 | const rows = await db |
| 577 | .select({ |
| 578 | id: workflowExecutionLogs.id, |
| 579 | workflowId: workflowExecutionLogs.workflowId, |
| 580 | workspaceId: workflowExecutionLogs.workspaceId, |
| 581 | executionId: workflowExecutionLogs.executionId, |
| 582 | level: workflowExecutionLogs.level, |
| 583 | trigger: workflowExecutionLogs.trigger, |
| 584 | startedAt: workflowExecutionLogs.startedAt, |
| 585 | endedAt: workflowExecutionLogs.endedAt, |
| 586 | totalDurationMs: workflowExecutionLogs.totalDurationMs, |
| 587 | executionData: workflowExecutionLogs.executionData, |
| 588 | costTotal: workflowExecutionLogs.costTotal, |
| 589 | workflowName: workflow.name, |
| 590 | }) |
| 591 | .from(workflowExecutionLogs) |
| 592 | .innerJoin(workflow, eq(workflowExecutionLogs.workflowId, workflow.id)) |
| 593 | .where(eq(workflowExecutionLogs.executionId, executionId)) |
| 594 | .limit(1) |
| 595 | |
| 596 | const log = rows?.[0] as any |
| 597 | if (!log) return null |
| 598 | |
| 599 | if (userId) { |
| 600 | const authorization = await authorizeWorkflowByWorkspacePermission({ |
| 601 | workflowId: log.workflowId, |
| 602 | userId, |
| 603 | action: 'read', |
| 604 | }) |
| 605 | if (!authorization.allowed) { |
| 606 | return null |
| 607 | } |
| 608 | if (currentWorkspaceId && authorization.workflow?.workspaceId !== currentWorkspaceId) { |
| 609 | return null |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | // Heavy execution data may live in object storage; resolve the pointer. |
| 614 | const { materializeExecutionData } = await import('@/lib/logs/execution/trace-store') |
| 615 | const executionData = (await materializeExecutionData( |
| 616 | log.executionData as Record<string, unknown> | null, |
| 617 | { workspaceId: log.workspaceId, workflowId: log.workflowId, executionId: log.executionId } |
| 618 | )) as any |
| 619 | |
| 620 | const summary = { |
| 621 | id: log.id, |
| 622 | workflowId: log.workflowId, |
| 623 | executionId: log.executionId, |
| 624 | level: log.level, |
| 625 | trigger: log.trigger, |
no test coverage detected