from typing import List, Optional
from armorer.agent_sdk import tool
from armorer.knowledge import KnowledgeBase

_kb = KnowledgeBase()

@tool(category="knowledge", verification_level="knowledge_lookup", safe_for_retrieval=True)
def search_knowledge(query: str) -> str:
    """
    Search the Armorer Knowledge Base for information on specific topics 
    like Docker, security best practices, or application-specific details.
    
    Args:
        query: The search keywords or question.
    """
    results = _kb.search(query)
    return results or "No relevant information found in the knowledge base."

@tool(category="knowledge", verification_level="knowledge_lookup", safe_for_retrieval=True)
def get_knowledge_topic(topic_name: str) -> str:
    """
    Retrieve the full content of a specific knowledge base topic.
    Use list_knowledge_topics to see what's available.
    
    Args:
        topic_name: The name of the topic (e.g., 'docker', 'openclaw').
    """
    content = _kb.get(topic_name)
    return content or f"Topic '{topic_name}' not found."

@tool(category="knowledge", verification_level="knowledge_lookup", safe_for_retrieval=True)
def list_knowledge_topics() -> List[str]:
    """
    List all available topics in the Armorer Knowledge Base.
    """
    return _kb.topics()
