import type { ToolboxTool } from "./Tool.js"; /** * Read-only, heterogeneous view of any tool regardless of its concrete arg * type. The search engine only reads covariant metadata (name, description, * aliases, searchHint) and never calls `execute`. A registry holds tools with * many different `TArgs`, and because `TArgs` sits in `execute`'s (contravariant) * parameter position, TypeScript has no single non-`any` supertype that accepts * every `ToolboxTool` — this is the standard existential-type limitation. * `` is the documented existential boundary (the same one the registry * uses for storage); it is confined to this read-only alias and never leaks a * real `any` into call sites, since every method only touches metadata fields. */ type AnyTool = ToolboxTool; /** * A single search result with its relevance score and match source. */ export interface SearchResult { tool: AnyTool; /** Relevance score where lower is better (0 = exact name match). */ score: number; /** Which field produced the best match for this tool. */ matchedOn: "name" | "description" | "searchHint" | "alias"; } /** * Stateless keyword search engine with TF-IDF-style scoring for ToolboxTool * arrays. All state comes from the `tools` parameter -- the class holds no * mutable data between calls. * * Scoring algorithm (lower is better): * 1. Exact tool name match -> 0 * 2. Tool name contains a query keyword -> 10 * 3. Alias matches a query keyword -> 15 * 4. searchHint contains a keyword -> 20 (minus 2 per extra match) * 5. Description contains a keyword -> 30 (minus 2 per extra match) * 6. Multiple keyword matches further reduce score */ export declare class ToolSearchEngine { /** * Search tools by keyword query. * * @param tools - The full tool collection to search against. * @param query - Free-text query (split on whitespace into keywords). * @param limit - Maximum number of results (default 10). * @returns Results sorted by relevance (best first, lowest score). */ search(tools: AnyTool[], query: string, limit?: number): SearchResult[]; /** * Direct select: find tools by exact name. * * Supports comma-separated names (the `select:Read,Edit,Grep` pattern). * The `select:` prefix is stripped automatically if present. * * @param tools - The full tool collection. * @param names - Comma-separated tool names, optionally prefixed with `select:`. * @returns Matched tools in the order they were requested (missing names are skipped). */ selectByName(tools: AnyTool[], names: string): AnyTool[]; /** * Tokenize a query string into lowercase keywords, filtering out tokens * shorter than {@link MIN_TOKEN_LENGTH} characters. */ private tokenize; /** * Score a single tool against the given keywords. * * Returns `null` when no keyword matches any searchable field, * meaning the tool should be excluded from results entirely. */ private scoreTool; private levenshtein; } export {};