Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

2.7 KB
Raw Blame
/**
 * Tool Icons Utility
 * Maps tool names and match types to icons for better UI display
 */
import i18n from '@/i18n'

const t = (key: string) => i18n.global.t(key)

// Tool name to icon mapping
export const toolIcons: Record<string, string> = {
    multi_kb_search: 'πŸ”',
    search_knowledge: 'πŸ“š',
    read_document: '🧩',
    list_documents: 'ℹ️',
    get_chunk_detail: 'πŸ“„',
    list_knowledge_bases: 'πŸ“‚',
    query_knowledge_graph: 'πŸ•ΈοΈ',
    think: 'πŸ’­',
    todo_write: 'πŸ“‹',
    // Retired names (still present in stored chat history)
    knowledge_search: 'πŸ“š',
    grep_chunks: 'πŸ”Ž',
    list_knowledge_chunks: '🧩',
    get_document_info: 'ℹ️',
};

// Match type internal keys for icon mapping
const matchTypeIconKeys: Record<string, string> = {
    vector: '🎯',
    keyword: 'πŸ”€',
    adjacent: 'πŸ“Œ',
    history: 'πŸ“œ',
    parent: '⬆️',
    relation: 'πŸ”—',
    graph: 'πŸ•ΈοΈ',
};

// Match type to icon mapping (keys match backend API response)
export const matchTypeIcons: Record<string, string> = {
    'Vector Match': '🎯',
    'Keyword Match': 'πŸ”€',
    'Adjacent Chunk Match': 'πŸ“Œ',
    'History Match': 'πŸ“œ',
    'Parent Chunk Match': '⬆️',
    'Relation Chunk Match': 'πŸ”—',
    'Graph Match': 'πŸ•ΈοΈ',
};

// Get icon for a tool name
export function getToolIcon(toolName: string): string {
    return toolIcons[toolName] || 'πŸ› οΈ';
}

// Get icon for a match type
export function getMatchTypeIcon(matchType: string): string {
    return matchTypeIcons[matchType] || matchTypeIconKeys[matchType] || 'πŸ“';
}

// Tool name to i18n key mapping
const toolDisplayNameKeys: Record<string, string> = {
    multi_kb_search: 'tools.multiKbSearch',
    search_knowledge: 'tools.searchKnowledge',
    read_document: 'tools.readDocument',
    list_documents: 'tools.listDocuments',
    get_chunk_detail: 'tools.getChunkDetail',
    list_knowledge_bases: 'tools.listKnowledgeBases',
    query_knowledge_graph: 'tools.queryKnowledgeGraph',
    think: 'tools.think',
    todo_write: 'tools.todoWrite',
    // Retired names (still present in stored chat history)
    knowledge_search: 'tools.knowledgeSearch',
    grep_chunks: 'tools.grepChunks',
    list_knowledge_chunks: 'tools.listKnowledgeChunks',
    get_document_info: 'tools.getDocumentInfo',
};

// Get tool display name (user-friendly, localized)
export function getToolDisplayName(toolName: string): string {
    const key = toolDisplayNameKeys[toolName];
    if (key) return t(key);

    // Format MCP tool names: "mcp_service_tool" β†’ "Service Tool"
    if (toolName.startsWith('mcp_')) {
        const parts = toolName.slice(4).split('_');
        return parts.map(p => p.charAt(0).toUpperCase() + p.slice(1)).join(' ');
    }

    return toolName;
}