MCPcopy
hub / github.com/StructuredLabs/preswald / workflow_dag

Function workflow_dag

preswald/interfaces/components.py:961–1023  ·  view source on GitHub ↗

Render the workflow's DAG visualization. Args: workflow: The workflow object to visualize title: Optional title for the visualization

(
        workflow: Workflow,
        title: str = "Workflow Dependency Graph",
        component_id: str | None = None,
        **kwargs
)

Source from the content-addressed store, hash-verified

959
960@with_render_tracking("workflow_dag")
961def workflow_dag(
962 workflow: Workflow,
963 title: str = "Workflow Dependency Graph",
964 component_id: str | None = None,
965 **kwargs
966) -> ComponentReturn:
967 """
968 Render the workflow's DAG visualization.
969
970 Args:
971 workflow: The workflow object to visualize
972 title: Optional title for the visualization
973 """
974 try:
975 from .workflow import WorkflowAnalyzer
976
977 analyzer = WorkflowAnalyzer(workflow)
978 analyzer.build_graph() # Ensure graph is built
979
980 # Get node data
981 nodes_data = []
982 for node, data in analyzer.graph.nodes(data=True):
983 nodes_data.append(
984 {
985 "name": node,
986 "status": data["status"],
987 "execution_time": data["execution_time"],
988 "attempts": data["attempts"],
989 "error": data["error"],
990 "dependencies": data["dependencies"],
991 "force_recompute": data["force_recompute"],
992 }
993 )
994
995 # Create the component with the correct type and data structure
996 component = {
997 "type": "dag", # Changed from "plot" to "dag"
998 "id": component_id,
999 "data": {
1000 "data": [
1001 {
1002 "type": "scatter",
1003 "customdata": nodes_data,
1004 "node": {"positions": []}, # Will be calculated by react-flow
1005 }
1006 ],
1007 "layout": {"title": {"text": title}, "showlegend": True},
1008 },
1009 }
1010
1011 logger.debug(f"[WORKFLOW_DAG] Created DAG component with id {component_id}")
1012 return ComponentReturn(component, component)
1013
1014 except Exception as e:
1015 logger.error(
1016 f"[WORKFLOW_DAG] Error creating DAG visualization: {e!s}", exc_info=True
1017 )
1018 error_component = {

Callers 1

workflow_dag_demoFunction · 0.90

Calls 3

build_graphMethod · 0.95
ComponentReturnClass · 0.90
WorkflowAnalyzerClass · 0.85

Tested by

no test coverage detected