# state.py
from typing import TypedDict, Annotated
from langgraph.graph.message import add_messages


class ClassifyEntry(TypedDict):
    type:  str   # RETRIEVAL | CODE_GENERATION | CONVERSATIONAL | PLATFORM
    topic: str   # brief subject extracted from the question (~60 chars)


class AgentState(TypedDict):
    # -- CORE
    messages:           Annotated[list, add_messages]
    reformulated_query: str
    context:            str
    query_type:         str
    session_id:         str
    # -- CLASSIFIER INTENT HISTORY
    # Compact trace of past decisions. Gives the classifier the conversation
    # thread without passing raw message content (which biases small models).
    classify_history:   list[ClassifyEntry]
    # -- OPEN AI API
    editor_content: str
    selected_text:  str
    extra_context:  str
    user_info: str
    use_editor_context: bool
    # -- PTVL (ADR-0009)
    parser_trace:       str   # raw parser error trace from first validation (empty if valid)
    validation_status:  str   # "" | "INVALID_UNRESOLVED" | "PARSER_UNAVAILABLE"
    context_relevant:   bool  # result of CONFIDENCE_PROMPT check (RETRIEVAL only)
    # -- TEST GENERATION
    test_inputs:        dict  # variables injected when executing generated code
    test_list:          list  # regex assertions validated against output variables