/** * `FirecrawlSearchProvider`: a `WebSearchProvider` backed by the Firecrawl search API * (`POST /v1/search`). It maps `title` to `title` and the `description` excerpt (bounded by * `maxSnippetChars`) to `snippet`, keeps citeable URL-only entries when no description is * present, and omits `content` because Firecrawl returns no generated answer. * @module @elves-ai/dsh-web-search-firecrawl/provider */ import type { WebSearchProvider, WebSearchRequest, WebSearchResult, WebSearchSource } from '@deepseek-ai/dsh-web'; import type { FirecrawlSearchDataItem, FirecrawlSearchResponse } from './types.ts'; export { FIRECRAWL_DEFAULT_BASE_URL, FIRECRAWL_DEFAULT_MAX_SNIPPET_CHARS, } from './settings-shared.ts'; /** Stable id this provider registers under. */ export declare const FIRECRAWL_PROVIDER_ID = "firecrawl"; /** Resolved provider options (the plugin's `apply` supplies env-var and constant defaults). */ export interface FirecrawlSearchProviderOptions { /** Firecrawl API key. Empty/absent makes the provider unavailable. */ apiKey: string; /** Endpoint base; `/v1/search` is appended. */ baseURL: string; /** Default result count when a request carries no `maxResults`. */ limit?: number; /** Upper bound on characters kept from one `description` when mapping `snippet`. */ maxSnippetChars: number; /** Route searches through Firecrawl; false delegates to {@link fallback}. */ useFirecrawl?: boolean; /** Original web-search provider used when `useFirecrawl` is false. */ fallback?: WebSearchProvider; } /** * Bound `text` to `max` characters. Firecrawl's `description` is frequently a long * page-markdown excerpt; the bound keeps one source's snippet from flooding model context * while preserving the excerpt's head. * * @param text - the excerpt to bound. * @param max - upper bound on the kept length. * @returns `text` unchanged when within the bound, else its first `max` characters. */ export declare function truncateTo(text: string, max: number): string; /** * Map one Firecrawl `data[]` entry to a normalized source. `description` is trimmed, * blank-checked, and bounded by `maxSnippetChars`; an entry without a non-blank description * still maps to a citeable URL-only source (the seam supports sources without snippets, as * Perplexity citations may be URL-only). * * @param item - one entry of Firecrawl's `data[]`. * @param maxSnippetChars - bound on the mapped snippet length. * @returns the normalized source. */ export declare function mapFirecrawlResult(item: FirecrawlSearchDataItem, maxSnippetChars: number): WebSearchSource; /** * Map a Firecrawl response envelope to a normalized search result. * * @param response - the parsed `POST /v1/search` response body. * @param maxSnippetChars - bound on one mapped snippet length. * @returns the normalized result. * @throws {@link WebError} `WEB_PROVIDER_ERROR` when the envelope reports failure. */ export declare function mapFirecrawlResponse(response: FirecrawlSearchResponse, maxSnippetChars: number): WebSearchResult; /** The Firecrawl-backed search provider; HTTP redirects fail as `WEB_PROVIDER_ERROR`. */ export declare class FirecrawlSearchProvider implements WebSearchProvider { private options; readonly id = "firecrawl"; constructor(options: FirecrawlSearchProviderOptions); /** * Replace the options used by the next `available()` / `search()` call. * The plugin host calls this when a settings-page commit resolves, so a * key or endpoint change reaches the already-registered provider without a * re-registration or a restart. */ setOptions(options: FirecrawlSearchProviderOptions): void; available(): boolean; search(request: WebSearchRequest, signal?: AbortSignal): Promise; }