types.ts•5.51 kB
export interface SearchResult {
title: string;
url: string;
snippet: string;
index: number;
}
export interface SearchResultsPage {
results: SearchResult[];
currentPage: number;
totalPages: number;
totalResults: number;
hasNextPage: boolean;
hasPreviousPage: boolean;
query: string;
nextPageParams?: Record<string, string>;
previousPageParams?: Record<string, string>;
}
export interface SearchStatistics {
totalResults: number;
currentPage: number;
totalPages: number;
resultsPerPage: number;
hasNextPage: boolean;
hasPreviousPage: boolean;
}
export interface SearchOptions {
locale?: string;
}
export interface Searcher {
/**
* Search for results with pagination support
* @param query The search query
* @param nextToken Optional next page token for pagination
* @param options Optional search options
* @returns Promise resolving to search results page
*/
search(query: string, nextToken?: string, options?: SearchOptions): Promise<SearchResultsPage>;
/**
* Get the next page of results
* @param currentPage Current search results page
* @returns Promise resolving to next page results
*/
getNextPage(currentPage: SearchResultsPage): Promise<SearchResultsPage>;
/**
* Get the previous page of results
* @param currentPage Current search results page
* @returns Promise resolving to previous page results
*/
getPreviousPage(currentPage: SearchResultsPage): Promise<SearchResultsPage>;
/**
* Get search statistics for the current query
* @param query The search query
* @param page Current page number
* @returns Promise resolving to search statistics
*/
getSearchStatistics(query: string, page: number): Promise<SearchStatistics>;
/**
* Check if a next page is available
* @param currentPage Current search results page
* @returns boolean indicating if next page exists
*/
hasNextPage(currentPage: SearchResultsPage): boolean;
/**
* Check if a previous page is available
* @param currentPage Current search results page
* @returns boolean indicating if previous page exists
*/
hasPreviousPage(currentPage: SearchResultsPage): boolean;
}
export interface ExtractedContent {
title: string;
url: string;
content: string;
extractedAt: string;
}
export interface Config {
verbose: boolean;
userAgent: string;
timeout: number;
maxRetries: number;
rateLimitDelay: number;
cacheEnabled: boolean;
maxResults: number;
log: (...args: any[]) => void;
}
export interface RCConfig {
userAgent?: string;
timeout?: number;
maxRetries?: number;
rateLimitDelay?: number;
cacheEnabled?: boolean;
maxResults?: number;
}
export interface CLIOptions {
url?: string;
verbose?: boolean;
github?: boolean;
language?: string;
extension?: string;
repo?: string;
user?: string;
org?: string;
filename?: string;
path?: string;
sort?: 'indexed' | 'created' | 'updated';
order?: 'asc' | 'desc';
mcp?: boolean;
}
export interface ContentMatch {
lineNumber: number;
content: string;
}
export type Platform = 'darwin' | 'win32' | 'linux';
// Exception classes for DuckDuckGo search
export class RatelimitException extends Error {
constructor(
public statusCode: number,
message: string = `Rate limit exceeded (HTTP ${statusCode})`
) {
super(message);
this.name = 'RatelimitException';
}
}
export class DuckDuckGoSearchException extends Error {
constructor(
public statusCode: number,
message: string = `DuckDuckGo search failed (HTTP ${statusCode})`
) {
super(message);
this.name = 'DuckDuckGoSearchException';
}
}
// GitHub Code Search types
export interface GitHubCodeSearchOptions {
sort?: 'indexed' | 'created' | 'updated';
order?: 'asc' | 'desc';
perPage?: number;
}
export interface GitHubCodeResult {
name: string;
path: string;
sha: string;
url: string;
git_url: string;
html_url: string;
score: number;
repository: {
id: number;
node_id: string;
name: string;
full_name: string;
owner: {
login: string;
id: number;
avatar_url: string;
html_url: string;
};
private: boolean;
html_url: string;
description: string | null;
language: string | null;
stargazers_count: number;
watchers_count: number;
forks_count: number;
};
text_matches?: {
object_url: string;
object_type: string;
property: string;
fragment: string;
matches: {
indices: [number, number];
text: string;
}[];
}[];
}
export interface GitHubCodeSearchResponse {
total_count: number;
incomplete_results: boolean;
items: GitHubCodeResult[];
}
// Code search query building
export interface CodeSearchQuery {
keywords: string[];
language?: string;
extension?: string;
filename?: string;
path?: string;
repo?: string;
user?: string;
org?: string;
size?: string;
in?: ('file' | 'path')[];
}
export interface ParsedCodeSearchInput {
query: CodeSearchQuery;
remainingKeywords: string[];
}
export class GitHubSearchException extends Error {
constructor(
public statusCode: number,
message: string = `GitHub search failed (HTTP ${statusCode})`
) {
super(message);
this.name = 'GitHubSearchException';
}
}
export class GitHubAuthException extends Error {
constructor(message: string = 'GitHub authentication required (gh auth login)') {
super(message);
this.name = 'GitHubAuthException';
}
}