Repository: Significant-Gravitas/Auto-GPT
File: autogpt_platform/backend/backend/data/graph.py (Python)

Code before:
            nodes=[Graph._process_node(node, hide_secrets) for node in nodes],
            links=list(
                {
                    Link.from_db(link)
                    for node in nodes
                    for link in (node.Input or []) + (node.Output or [])
                }
            ),
            subgraphs={
                subgraph.id: [node.id for node in subgraph.AgentNodes or []]
                for subgraph in graph.AgentSubGraphs or []
            },
        )

    @staticmethod
    def _process_node(node: AgentNode, hide_secrets: bool) -> Node:
        node_dict = node.model_dump()
        if hide_secrets and "constantInput" in node_dict:
            constant_input = json.loads(node_dict["constantInput"])
            Graph._hide_secrets_in_input(constant_input)
            node_dict["constantInput"] = json.dumps(constant_input)
        return Node.from_db(AgentNode(**node_dict))

    @staticmethod
    def _hide_secrets_in_input(input_data: Dict[str, Any]):
        sensitive_keys = ["api_key", "password", "token", "secret"]
        for key, value in input_data.items():
            if isinstance(value, dict):
                Graph._hide_secrets_in_input(value)
            elif isinstance(value, str) and any(
                sensitive_key in key.lower() for sensitive_key in sensitive_keys
            ):
                input_data[key] = "*******"


AGENT_NODE_INCLUDE: prisma.types.AgentNodeInclude = {
    "Input": True,
    "Output": True,
    "AgentBlock": True,
}

__SUBGRAPH_INCLUDE = {"AgentNodes": {"include": AGENT_NODE_INCLUDE}}

AGENT_GRAPH_INCLUDE: prisma.types.AgentGraphInclude = {
    **__SUBGRAPH_INCLUDE,
    "AgentSubGraphs": {"include": __SUBGRAPH_INCLUDE},  # type: ignore
}


# --------------------- Model functions --------------------- #


Review comment (security):
```suggestion
        sensitive_keys = ["credentials", "api_key", "password", "token", "secret"]
```

Code after:
            nodes=[Graph._process_node(node, hide_credentials) for node in nodes],
            links=list(
                {
                    Link.from_db(link)
                    for node in nodes
                    for link in (node.Input or []) + (node.Output or [])
                }
            ),
            subgraphs={
                subgraph.id: [node.id for node in subgraph.AgentNodes or []]
                for subgraph in graph.AgentSubGraphs or []
            },
        )

    @staticmethod
    def _process_node(node: AgentNode, hide_credentials: bool) -> Node:
        node_dict = node.model_dump()
        if hide_credentials and "constantInput" in node_dict:
            constant_input = json.loads(node_dict["constantInput"])
            Graph._hide_credentials_in_input(constant_input)
            node_dict["constantInput"] = json.dumps(constant_input)
        return Node.from_db(AgentNode(**node_dict))

    @staticmethod
    def _hide_credentials_in_input(input_data: dict[str, Any]):
        sensitive_keys = ["credentials", "api_key", "password", "token", "secret"]
        for key, value in input_data.items():
            if isinstance(value, dict):
                Graph._hide_credentials_in_input(value)
            elif isinstance(value, str) and any(
                sensitive_key in key.lower() for sensitive_key in sensitive_keys
            ):
                del input_data[key]


AGENT_NODE_INCLUDE: prisma.types.AgentNodeInclude = {
    "Input": True,
    "Output": True,
    "AgentBlock": True,
}

__SUBGRAPH_INCLUDE = {"AgentNodes": {"include": AGENT_NODE_INCLUDE}}

AGENT_GRAPH_INCLUDE: prisma.types.AgentGraphInclude = {
    **__SUBGRAPH_INCLUDE,
    "AgentSubGraphs": {"include": __SUBGRAPH_INCLUDE},  # type: ignore
}


# --------------------- Model functions --------------------- #