def display_messages()

in src/frontends/streamlit_adk/frontend/streamlit_app.py [0:0]


def display_messages() -> None:
    """Display all messages in the current chat session."""
    messages = st.session_state.user_chats[st.session_state["session_id"]]["messages"]
    tool_calls_map = {}  # Map tool_call_id to tool call input
    for i, message in enumerate(messages):
        # Convert message to Event if it's not already
        event = message if isinstance(message, Event) else Event.model_validate(message)

        # Check if this is a model message with function calls
        if hasattr(event.content, "parts") and event.content.parts:
            for part in event.content.parts:
                if hasattr(part, "function_call") and part.function_call:
                    # Store function call info for later matching with responses
                    tool_calls_map[part.function_call.id] = {
                        "id": part.function_call.id,
                        "name": part.function_call.name,
                        "args": part.function_call.args,
                    }

        # Check if this is a message with function responses
        function_responses = []
        if hasattr(event.content, "parts") and event.content.parts:
            for part in event.content.parts:
                if hasattr(part, "function_response") and part.function_response:
                    function_responses.append(part.function_response)

        # Display function responses if any
        for function_response in function_responses:
            tool_call_id = function_response.id
            if tool_call_id in tool_calls_map:
                # Display the tool output and remove from map
                tool_call = tool_calls_map.pop(tool_call_id, None)
                if tool_call:
                    display_tool_output(
                        tool_call,
                        {
                            "type": "tool",
                            "content": function_response.response,
                            "tool_call_id": tool_call_id,
                        },
                    )

        # Display regular chat messages (model or user)
        if hasattr(event.content, "role") and event.content.role in ["model", "user"]:
            # Only display if there's text content (skip pure function call messages)
            has_text_content = False
            if hasattr(event.content, "parts"):
                for part in event.content.parts:
                    if hasattr(part, "text") and part.text:
                        has_text_content = True
                        break

            if has_text_content:
                display_chat_message(message, i)