Source code for haive.core.common.structures.tree_leaf.auto

"""Auto-tree functionality for automatic tree generation from BaseModels.

This module provides the AutoTree class that automatically generates tree
structures from Pydantic BaseModels, handling nested structures and Union types.
"""

from collections.abc import Callable
from typing import TypeVar

from pydantic import BaseModel

from haive.core.common.structures.tree_leaf.base import Leaf, TreeNode
from haive.core.common.structures.tree_leaf.generics import DefaultContent, DefaultResult

T = TypeVar("T", bound=BaseModel)


[docs] class AutoTree: """Placeholder for AutoTree functionality. TODO: Implement auto-tree generation from BaseModel inspection. """
[docs] def auto_tree( model: T, content_extractor: Callable[[BaseModel], BaseModel] | None = None ) -> TreeNode[DefaultContent, DefaultResult]: """Create a tree structure automatically from a BaseModel instance. Args: model: The BaseModel instance to convert to a tree. content_extractor: Optional function to extract content from models. Returns: A TreeNode representing the model structure. """ # TODO: Implement auto-tree generation return Leaf(content=DefaultContent(name=model.__class__.__name__))