"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.register = register;
const zod_1 = require("zod");
const defaults_1 = require("../../../lib/defaults");
function register(server, mgr) {
    server.registerTool('notes_search', {
        description: 'Semantic search over the knowledge graph (facts and notes). ' +
            'Supports three modes: hybrid (default, BM25 + vector), vector, keyword. ' +
            'Finds the most relevant notes, then expands results ' +
            'by traversing relations between notes (graph walk). ' +
            'Returns an array sorted by relevance score (0–1), each with: ' +
            'id, title, content, tags, score.',
        inputSchema: {
            query: zod_1.z.string().max(defaults_1.MAX_SEARCH_QUERY_LEN).describe('Natural language search query'),
            topK: zod_1.z.number().min(1).max(500).optional().describe('How many top similar notes to use as seeds (default 5)'),
            bfsDepth: zod_1.z.number().min(0).max(10).optional().describe('How many hops to follow relations from each seed (default 1; 0 = no expansion)'),
            maxResults: zod_1.z.number().min(1).max(500).optional().describe('Maximum number of results to return'),
            minScore: zod_1.z.number().min(0).max(1).optional().describe('Minimum relevance score 0–1 (default 0.5)'),
            bfsDecay: zod_1.z.number().min(0).max(1).optional().describe('Score multiplier per hop (default 0.8)'),
            searchMode: zod_1.z.enum(['hybrid', 'vector', 'keyword']).optional().describe('Search mode: hybrid (default, BM25 + vector), vector (embedding only), keyword (BM25 only)'),
        },
    }, async ({ query, topK, bfsDepth, maxResults, minScore, bfsDecay, searchMode }) => {
        const results = await mgr.searchNotes(query, { topK, bfsDepth, maxResults, minScore, bfsDecay, searchMode });
        const clean = (k, v) => (k !== '' && Array.isArray(v) && v.length === 0 ? undefined : v);
        return { content: [{ type: 'text', text: JSON.stringify(results, clean, 2) }] };
    });
}
