2025-04-17 01:03:45 +03:00
|
|
|
import { SearchResponse, SearchResult } from "./types.js";
|
2025-04-03 11:50:02 +03:00
|
|
|
|
|
|
|
/**
|
2025-04-17 01:03:45 +03:00
|
|
|
* Format a search result into a string representation
|
|
|
|
* @param result SearchResult to format
|
|
|
|
* @returns Formatted search result string
|
2025-04-03 11:50:02 +03:00
|
|
|
*/
|
2025-04-17 01:03:45 +03:00
|
|
|
export function formatSearchResult(result: SearchResult): string {
|
2025-05-02 00:09:19 +03:00
|
|
|
return `- Title: ${result.title}
|
|
|
|
- Context7-compatible library ID: ${result.id}
|
|
|
|
- Description: ${result.description}
|
|
|
|
- Code Snippets: ${result.totalSnippets}
|
|
|
|
- GitHub Stars: ${result.stars}`;
|
2025-04-03 11:50:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2025-04-17 01:03:45 +03:00
|
|
|
* Format search results into a string representation
|
|
|
|
* @param searchResponse The search response to format
|
|
|
|
* @returns Formatted search results string
|
2025-04-03 11:50:02 +03:00
|
|
|
*/
|
2025-04-17 01:03:45 +03:00
|
|
|
export function formatSearchResults(searchResponse: SearchResponse): string {
|
|
|
|
if (!searchResponse.results || searchResponse.results.length === 0) {
|
|
|
|
return "No documentation libraries found matching your query.";
|
2025-04-08 13:50:44 +03:00
|
|
|
}
|
|
|
|
|
2025-04-17 01:03:45 +03:00
|
|
|
const formattedResults = searchResponse.results.map(formatSearchResult);
|
2025-05-02 00:09:19 +03:00
|
|
|
return formattedResults.join("\n---\n");
|
2025-04-08 13:50:44 +03:00
|
|
|
}
|