src / adapters / SiteAdapter.ts
import { ExtractedWebpage } from "../cache/WebpageCache";
import { HTTPClient } from "../http/HTTPClient";
export interface AdapterContext {
/** The original validated target URL requested by the caller */
originalUrl: string;
/** Parsed URL object of originalUrl */
parsedUrl: URL;
/** Shared HTTPClient instance enforcing security & DNS validation */
httpClient: HTTPClient;
/** Raw mode flag passed from tool call */
rawMode?: boolean;
}
export interface AdapterResult {
/** Extracted webpage object ready for caching & downstream windowing */
extracted: ExtractedWebpage;
/** Actual URL fetched if URL rewriting occurred (e.g. old.reddit.com) */
actualFetchUrl?: string;
/** Identifier of the adapter that processed the request */
adapterName: string;
}
export interface SiteAdapter {
/** Unique identifier for the adapter (e.g., "RedditAdapter") */
name: string;
/** Cheap, synchronous hostname/pattern match check */
matches(parsedUrl: URL): boolean;
/** Executes site-specific fetching & extraction strategy */
extract(context: AdapterContext): Promise<AdapterResult>;
}
src / adapters / SiteAdapter.ts
import { ExtractedWebpage } from "../cache/WebpageCache";
import { HTTPClient } from "../http/HTTPClient";
export interface AdapterContext {
/** The original validated target URL requested by the caller */
originalUrl: string;
/** Parsed URL object of originalUrl */
parsedUrl: URL;
/** Shared HTTPClient instance enforcing security & DNS validation */
httpClient: HTTPClient;
/** Raw mode flag passed from tool call */
rawMode?: boolean;
}
export interface AdapterResult {
/** Extracted webpage object ready for caching & downstream windowing */
extracted: ExtractedWebpage;
/** Actual URL fetched if URL rewriting occurred (e.g. old.reddit.com) */
actualFetchUrl?: string;
/** Identifier of the adapter that processed the request */
adapterName: string;
}
export interface SiteAdapter {
/** Unique identifier for the adapter (e.g., "RedditAdapter") */
name: string;
/** Cheap, synchronous hostname/pattern match check */
matches(parsedUrl: URL): boolean;
/** Executes site-specific fetching & extraction strategy */
extract(context: AdapterContext): Promise<AdapterResult>;
}