""" 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"""
{escape_html_content(path_desc)}
Click a node in the tree above to annotate it. Node annotation type: {escape_html_content(node_type)}