"""Node helpers — shared utilities used across node modules.

Pure functions. No node classes here. No Any.
"""

from core.common import JsonObject


def normalize_schema_fields(raw: JsonObject) -> JsonObject:
    """Normalize an input/output schema dict into flat {field_name: field_spec}.

    Handles three formats:
      1. Simple:  {"goal": "string", "tools": "array"}
      2. Full JSON Schema: {"type": "object", "properties": {"goal": {"type": "string"}}}
      3. Empty dict: {}

    Returns a flat dict of field_name -> type_or_spec suitable for validation.
    """
    if not raw:
        return {}
    props = raw.get("properties")
    if isinstance(props, dict):
        return props
    if raw.get("type") == "object" and "properties" not in raw:
        return {}
    return raw


__all__ = [
    "normalize_schema_fields",
]
