from __future__ import annotations

import asyncio

from app.modules.agent.observability.module_trace import ModuleTrace
from app.modules.agent.llm.service import AgentLlmService


class LlmChatAdapter:
    def __init__(self, llm: AgentLlmService, prompt_name: str = "simple_llm_answer") -> None:
        self._llm = llm
        self._prompt_name = prompt_name

    @property
    def prompt_name(self) -> str:
        return self._prompt_name

    def build_request(self, message: str, request_id: str) -> dict[str, str]:
        return self._llm.build_request(
            self._prompt_name,
            message,
            log_context=f"agent:{request_id}",
        )

    async def generate(self, message: str, request_id: str, trace: ModuleTrace | None = None) -> str:
        return await asyncio.to_thread(
            self._llm.generate,
            self._prompt_name,
            message,
            log_context=f"agent:{request_id}",
            trace=trace,
        )
