Source code for haive.core.common.structures.tree_leaf.generics
"""Generic type definitions for tree structures.Provides TypeVars with proper bounds and defaults for maximum flexibility."""fromtypingimportAny,TypeVarfrompydanticimportBaseModel# Basic content type - what each node containsContentT=TypeVar("ContentT",bound=BaseModel)# Child type - what type of children a branch can have# This allows mixed trees (e.g., branches containing both leaves and branches)ChildT=TypeVar("ChildT",bound=BaseModel)# Result type - what executing a node producesResultT=TypeVar("ResultT")# Default types for common use cases
[docs]classDefaultContent(BaseModel):"""Default content type with just a name/value."""name:strvalue:Any=None
[docs]classDefaultResult(BaseModel):"""Default result type with status and data."""success:booldata:Any=Noneerror:str|None=None
# Bounded TypeVars for specific use casesPlanContentT=TypeVar("PlanContentT",bound="PlanContent")TaskContentT=TypeVar("TaskContentT",bound="TaskContent")# Forward references for planning use caseclassPlanContent(BaseModel):"""Content type for planning trees."""objective:strdescription:str=""classTaskContent(BaseModel):"""Content type for task trees."""name:straction:strparams:dict[str,Any]={}