""" Tree Annotation Layout Generates annotation interface for conversation tree structures. Supports per-node annotation, path selection, and branch comparison. Users can: - Annotate individual nodes (e.g., rate each response) - Select preferred paths through the tree - Compare branches at decision points """ import json import logging from .identifier_utils import ( safe_generate_layout, escape_html_content, ) logger = logging.getLogger(__name__) def _generate_tree_annotation_layout_internal(annotation_scheme, horizontal=False): """ Internal function to generate tree annotation layout. Args: annotation_scheme: Configuration dictionary containing: - name: Schema identifier - description: Description shown to user - node_scheme: Annotation scheme config for per-node annotation (e.g., {annotation_type: "likert", size: 5, ...}) - path_selection: - enabled: Whether path selection is enabled - description: Instruction text for path selection - branch_comparison: - enabled: Whether branch comparison is enabled Returns: tuple: (HTML string, key bindings list) """ scheme_name = annotation_scheme["name"] description = annotation_scheme.get("description", "Annotate the conversation tree") node_scheme = annotation_scheme.get("node_scheme", {}) path_selection = annotation_scheme.get("path_selection", {}) branch_comparison = annotation_scheme.get("branch_comparison", {}) path_enabled = path_selection.get("enabled", False) path_desc = path_selection.get("description", "Select the best response path") branch_enabled = branch_comparison.get("enabled", False) config_data = json.dumps({ "schemaName": scheme_name, "nodeScheme": node_scheme, "pathSelection": { "enabled": path_enabled, "description": path_desc, }, "branchComparison": { "enabled": branch_enabled, }, }) # Path selection section path_section = "" if path_enabled: path_section = f"""
Path Selection

{escape_html_content(path_desc)}

No path selected. Click on nodes in the tree to build a path.
""" # Node annotation mode description node_ann_desc = "" if node_scheme: node_type = node_scheme.get("annotation_type", "") node_ann_desc = f"""

Click a node in the tree above to annotate it. Node annotation type: {escape_html_content(node_type)}

""" schematic = f"""

{escape_html_content(description)}

{node_ann_desc} {path_section}
""" key_bindings = [] return schematic, key_bindings def generate_tree_annotation_layout(annotation_scheme, horizontal=False): """ Generate tree annotation layout HTML. Args: annotation_scheme (dict): The annotation scheme configuration horizontal (bool): Whether to display horizontally Returns: tuple: (HTML string, key bindings list) """ return safe_generate_layout( annotation_scheme, _generate_tree_annotation_layout_internal, horizontal )